查看/表格:
<%= 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_attributesendclass Club < ActiveRecord::Base has_many :members,:through=>:memberships has_many :membershipsendclass Memberships < ActiveRecord::Base belongs_to :Member belongs_to :Clubend解决方法
<%= f.fIElds_for :memberships do |m| %> <%= m.text_fIEld :task %> <%= m.fIElds_for :clubs do |s| %> <%= s.text_fIEld :name %> <% end %><% end %>总结
以上是内存溢出为你收集整理的ruby-on-rails – 如何在表单中包含Rails连接表字段?全部内容,希望文章能够帮你解决ruby-on-rails – 如何在表单中包含Rails连接表字段?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)