0

我有 2 个嵌套表格,例如 Estates 有收入,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 个提交按钮?

4

1 回答 1

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标记和对象更新的示例。但是,您可以修改它以生成对象(创建)。

于 2013-06-17T13:51:01.267 回答