用于提交嵌套设计用户数据的表单

时间:2014-01-17 21:21:51

标签: ruby-on-rails ruby-on-rails-3 devise nested-attributes

我有以下型号:

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :encryptable

  belongs_to :club
end

class Club < ActiveRecord::Base
  has_many :users

  accepts_nested_attributes_for :users
end

鉴于“accepts_nested_attributes_for”必须在“has_many”方面,我该如何构建一个接受嵌套,设计,用户数据的嵌套表单?

1 个答案:

答案 0 :(得分:1)

确定。我认为它应该有效:

控制器:

  

@users = @ club.users.build

表格:

 form_for @club
  fields_for @users |fr|
    @users.each do |usr|
      text_field :email
      text_field :password
      text_field :pass_conf...
          other fields
    end
   end
   submit
  end