我有2个嵌套表单,以便Estates有Revenue和Estates有费用,当前表单签名看起来像费用“<%= form_for [@estate,@expense] do |f| %>
”和收入“<%= form_for [@estate,@revenue] do |f| %>
”。我的路线是
resources :estates do
resources :revenues
resources :expenses
resources :net_profits
end
现在我可以点击这两个表单上的1个新按钮和1个提交按钮在同一页面上打开收入和费用表吗?
答案 0 :(得分:0)
首先,您需要在模型Estate
中添加以下内容:
accepts_nested_attributes_for :revenue
accepts_nested_attributes_for :expense
然后你可以用这样的form_for
生成它:
= form_for(@estate, :url => {:action=>'update'}) do |f|
= f.fields_for :revenue do |r|
# revenue fields here, for example:
= r.text_field :name
= f.fields_for :expense do |e|
# expense fields here, for example:
= e.text_field :name
这是HAML标记和对象更新的示例。但是,您可以修改它以进行对象生成(创建)。