我的路线是:
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发布于 2016-09-28 11:42:27
您应该传递post_id参数:
get :index, post_id: @post.id编辑
在您用我们可以看到的正确信息更新了问题之后,您的代码中存在一些问题:
@post = Post.find(params[:post_id]) # should be Post.find(params[:id])
@calculations = @post.something + 1 # thus this is `nil` + 1 - errorhttps://stackoverflow.com/questions/39745433
复制相似问题