在这种情况下,我可以将值插入到 Member 表和 Club 表中。但是在我想提交一个值:task
的表中有一个名为的字段,并且在 Memberships 表中并由Rails 自动插入。如何在下面的表格中包含该字段?先感谢您。memberships
member_id
club_id
task
查看/表格:
<%= form_for @member ,:url=>{:action =>"create"} do |f| %>
<%= f.text_field :email %>
<%= f.fields_for :clubs do |s| %>
<%= s.text_field :name %>
<% end %>
<%= f.submit "submit" %>
<% end %>
楷模
class Member < ActiveRecord::Base
has_many :clubs ,:through=> :memberships
has_many :memberships
accepts_nested_attributes_for :clubs
attr_accessible :clubs_attributes
end
class Club < ActiveRecord::Base
has_many :members ,:through=>:memberships
has_many :memberships
end
class Memberships < ActiveRecord::Base
belongs_to :Member
belongs_to :Club
end