ネストされた属性を使用して、1つのフォームでOrganization
とを作成しようとしています。User
次のエラーが発生します:保護された属性を一括割り当てできません:user(ActiveModel :: MassAssignmentSecurity :: Error)
これで髪を抜く
Organisation.rb
class Organization < ActiveRecord::Base
attr_accessible :name, :users_attributes
has_many :users, dependent: :destroy
accepts_nested_attributes_for :users
end
user.rb(deviseを使用)
class User < ActiveRecord::Base
attr_accessible :email
belongs_to :organization
end
new.html.haml
= form_for @organization do |f|
= f.label :name, "Company Name"
= f.text_field :name, placeholder: "Company Name"
= f.fields_for :user do |ff| -# tried :users here and the form doesn't render
= ff.label :email, "Email Address"
= ff.email_field :email, placeholder: "Email Address"
= f.submit "Create Account"