Rails - 调试嵌套路由
我有 2 个模型:评估和问题。评估有很多问题。
在路线中,我有:
map.resources :assessments, :has_many => :questions
map.root :assessments
我检查了 rake 路线,它符合预期
在创建新问题的表单上,我收到以下错误:
undefined method `questions_path' for #<ActionView::Base:0x6d3cdb8>
如果我取出表单,视图加载正常,所以我认为这是代码中的内容此视图-我在 form_for 行上收到错误:
<h1>New question</h1>
<% form_for [@assessment, @question] do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :content %><br />
<%= f.text_field :content %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Cancel', assessment_path(@assessment) %>
Rake Routes - http:// Pastebin.com/6fKUPTjq
询问控制器的代码 - http://pastebin.com/URzpmEcg
代码到评估控制器 - http://pastebin.com/HstvFTq4
任何人都可以帮我调试它吗?谢谢!
I have 2 models, Assessments and Questions. Assessments have many questions.
In routes, I have:
map.resources :assessments, :has_many => :questions
map.root :assessments
I checked rake routes, it's as expected
On the form to create a new question, I get the following error:
undefined method `questions_path' for #<ActionView::Base:0x6d3cdb8>
If I take out the form, the view loads fine, so I think it's something with the code in this view - I'm getting the error on the form_for line:
<h1>New question</h1>
<% form_for [@assessment, @question] do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :content %><br />
<%= f.text_field :content %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Cancel', assessment_path(@assessment) %>
Rake Routes - http://pastebin.com/6fKUPTjq
Code to question controller - http://pastebin.com/URzpmEcg
Code to assessment controller - http://pastebin.com/HstvFTq4
Can anyone help me debug it? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要
在控制器中。否则,
@assessment
为nil
。You need to have
in the controller. Otherwise,
@assessment
isnil
.