从视图中多次插入表中

时间:2012-08-06 21:49:03

标签: ruby-on-rails-3

我有以下课程

class TableA < ActiveRecord::Base
       has_one :tableb
end
class TableB < < ActiveRecord::Base
       belongs_to :tableA
end

我有一张tableA / form.html.erb

<%= form_for(@@table) do |f| %>
    <%= f.text_field :tableAColumn %>
    <%= f.text_field :tableAColumn1 %>
    #how can i how this 
    <%= f.text_field :tableBColumn %>
    <%=f.text_field :tableBColumn1 %>
    <%= f.submit %>
<%end>

因此,当我点击保存时,两个记录都可以保存在表A和表B中。

由于

1 个答案:

答案 0 :(得分:0)

我使用accepts_nested_attributes_for

Nested Attributes

相关问题