2014-11-20 205 views
0

我的路線,看起來像這樣:的Rails的form_tag嵌套嵌套資源

resources :teams do 

    resources :plans do 
    resources :charges 
    end 

    ... 

我想創建使用form_tag指向我charges_controller創建行動的形式。但我需要一些幫助......

目前我已經是這樣的(這只是一個按鈕,提交以JavaScript完成的)形式:

= form_tag team_plan_charges_path([@team, plan]) do 
    = content_tag "button", id: "customButton", class: "btn btn-primary" do 
    Select plan 

這將導致以下錯誤:

No route matches {:action=>"index", :controller=>"charges" ... missing required keys: [:plan_id] 

我不知道如何正確設置form_tag基於我的形式,任何想法?

+0

看起來不錯,試試'的form_tag team_plan_charges_path(@team,計劃),方法:POST' – 2014-11-20 21:05:57

+0

嘗試'耙routes',結果粘貼。 – tokhi 2014-11-20 22:17:22

回答

1

應該是這樣的:

= form_tag @charge, team_plan_charge_path([@team, @plan]), method: :post do 
    = content_tag "button", id: "customButton", class: "btn btn-primary" do 
    Select plan 
0

我認爲,team_plan_charges_path([@team, plan])應該像team_plan_charges_path([@team, @plan, @charges]) 其中@plan和@charges應該在您的費用控制,像

@plan = @team.plans.new 
@charges = @plan.charges.new 

假設你有計劃之間的關聯的has_many 計劃收費。 我也假設該計劃是不是有些方法在助手並按照該意見,你有一個method: :post 是一般的想法,因爲你的路由看起來像/團隊/:團隊:ID /計劃/:plan_id的數據類型/費用大概。

這裏是一個example來看看。