【发布时间】:2018-09-03 11:42:07
【问题描述】:
我在文件夹 (api/v1/) 中有我的主题控制器
class Api::V1::TopicsController < ApplicationController
def index
@topics = Topic.all
render json: @topics
end
end
当我尝试为上述代码编写 rspec 时:
require 'rails_helper'
require 'spec_helper'
RSpec.describe Api::V1::TopicsController do
describe "GET #index" do
it "should return a successful response" do
get :index, format: :json
expect(response).to be_success
end
end
end
我收到错误:
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"api/v1/topics", :format=>:json}.
但是我有正确的路线我不知道为什么它会这样显示。任何解决方案都是最受欢迎的。
我的路线如下:
Rails.application.routes.draw do
namespace :api, defaluts: {format: :json} do
namespace :v1 do
resources :topics
end
end
end
【问题讨论】:
-
也显示路线
-
我已经设置了我的路线
标签: ruby-on-rails rspec