[英]Rails 4 simple_form_for and nested resources undefined method
我收到未定義的方法錯誤:
undefined method `challenges_path'
我以為我的表格格式正確, _form.haml
= simple_form_for [@skit, @challenge], html: { class: "form-horizontal" } do |f|
上面表格的鏈接:
= link_to 'Submit', new_skit_challenge_path(params[:skit_id]), class: "btn btn-default"
這是我的路線
resources :skits do
resources :challenges
end
這是我的challenge_controller.rb
def new
@challenge = Challenge.new
end
我究竟做錯了什么? 您還需要哪些其他信息來幫助調試此問題?
也許您可以嘗試這樣做:
resources :skits, shallow: true do
resources :challenges
end
未定義的方法“ challenges_path”
問題是@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.