4
在這種情況下,我可以將值插入成員表和俱樂部表。但是在memberships
表中有一個名爲:task
的字段,我想向其提交一個值,並且在會員表中member_id
和club_id
由Rails自動插入。我如何在下面的表格中包含task
字段?先謝謝你。我如何在表單中包含Rails連接表字段?
查看/形式:
<%= 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
謝謝@DGM你會在控制器中加入,使這個可能嗎? – BKSpurgeon 2016-06-10 03:18:21