Ruby on rails 无法在创建操作时处理通过链接传递到url的Id

Ruby on rails 无法在创建操作时处理通过链接传递到url的Id,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有一个链接,我想通过URL传递一个id,以便在其他模型的操作(如new和create)中处理它 in_response.html.erb <%= link_to "Reply", new_subcomment_path(:response_id => response.id), id: "new_subcomment"%> 这是我的路线文件: resources :tasks do resources :responses end resources :respons

我有一个链接,我想通过URL传递一个id,以便在其他模型的操作(如new和create)中处理它

in_response.html.erb

<%= link_to "Reply", new_subcomment_path(:response_id => response.id), id: "new_subcomment"%>
这是我的路线文件:

resources :tasks do
  resources :responses 
end
resources :responses do
  resources :subcomments
end
resources :subcomments
我真的很好奇我传递的链接和参数有什么问题,因为它似乎无法在创建操作中处理。
请帮我找出这里出了什么问题>您的问题在创建操作的第一行:@response=response.findparams[:response\u id]。您正在尝试查找带有params params[:response_id]的记录,但上面的返回值为nil,因此错误无法找到没有id的响应


就好像你在做Respond.findnil一样。检查你的情妇;响应id可能不存在或以不同的方式嵌套。

您的表单没有响应id的位置,因此无法将其提交到创建操作,在您的简单表单中添加一行,如:

<%= f.hidden :response_id %>
但请注意:通过这样做,用户可以更改此值,我认为这对您和您的业务逻辑来说都不是问题,因为您已经接受了链接到新操作的响应id

resources :tasks do
  resources :responses 
end
resources :responses do
  resources :subcomments
end
resources :subcomments
<%= f.hidden :response_id %>