我有一些rails嵌套形式
= form_for @model do |f|
...
= f.fields_for :user_partnership do |builder|
- user_partners.each do |index|
= builder.hidden_field :user_partner_id
= content_tag(:li,index.name)
在我的model
我已经设置了has_many :user_partner, through: :users_partnership
.
fields_for
所以现在我有两个问题:第一个,我在进程内部没有输入。所以,在一些SO
帖子之后,我不得不添加这个
@model = model.new
@user_partners = User_Partner.all
@user_partners.count.times{@model.users_partnership.build}
但这真的很尴尬。第二个问题是如何获得fields_for
块的枚举数以便我可以正确设置index.name
?
编辑,这是我的模型
class model
has_many :user_partners, through: :users_partnerships
accepts_nested_attributes_for :users_partnerships
end
class User_Partner
has_many :models, through: :users_partnerships
end
class Users_Partnership
belongs_to :model
belongs_to :user_partner
end