[英]Rails 4 simple_form_for and nested resources undefined method
I'm getting undefined method error: 我收到未定义的方法错误:
undefined method `challenges_path'
I thought I had my form correct, _form.haml 我以为我的表格格式正确, _form.haml
= simple_form_for [@skit, @challenge], html: { class: "form-horizontal" } do |f|
The link to the form above: 上面表格的链接:
= link_to 'Submit', new_skit_challenge_path(params[:skit_id]), class: "btn btn-default"
This is my routes 这是我的路线
resources :skits do
resources :challenges
end
This is my challenge_controller.rb 这是我的challenge_controller.rb
def new
@challenge = Challenge.new
end
What am I doing wrong? 我究竟做错了什么? What else information do you need that can help debug this issue?
您还需要哪些其他信息来帮助调试此问题?
Perhaps you could try doing this: 也许您可以尝试这样做:
resources :skits, shallow: true do
resources :challenges
end
undefined method `challenges_path'
未定义的方法“ challenges_path”
The problem is @skit
is nil
because you haven't initialized @skit
in the new
action. 问题是
@skit
为nil
因为您尚未在new
操作中初始化@skit
。
def new
@challenge = Challenge.new
@skit = Skit.find(params[:skit_id]) #you need this line
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.