【发布时间】:2016-09-28 10:53:28
【问题描述】:
我的路线是:
resources :posts
resources :images
end
我想为 ImagesController 编写规范:
it "renders the index template" do
get :index, {:id => @post.id}
expect(response).to render_template("index")
end
错误是
No route matches {:action=>"index", :controller=>"images", :id=>"19"}
我该如何解决这个问题?
编辑:
用post_id 修复,但似乎仍然没有得到参数:
新的错误是
Failure/Error: get :index, {post_id: @post.id}
NoMethodError: undefined method `+' for nil:NilClass
索引视图:
def index
@post = Post.find(params[:post_id])
@calculations = @post.something + 1
end
【问题讨论】:
-
get :index, :post_id => @post.id -
@AndreyDeineko
Failure/Error: get :index, {:post_id => @post.id} NoMethodError: undefined method+' for nil:NilClass` 我当然定义了@post -
你认为我可以帮你做最新的吗?至少它不再说没有路线,所以它解决了问题
-
我可以添加它作为答案,你可以接受它然后再问一个新的,除非你自己明白哪里出了问题
-
您无法即时更改您的问题。最初你收到
No route match错误,我帮你解决了。这是另一个问题,因为它暴露了不同的问题。
标签: ruby-on-rails ruby-on-rails-4 routing routes