Can't mass-assign protected attributes: user
Posted
by
Ben Aluan
on Stack Overflow
See other posts from Stack Overflow
or by Ben Aluan
Published on 2012-09-16T14:58:14Z
Indexed on
2012/09/16
15:37 UTC
Read the original article
Hit count: 271
I'm working on a simple app that requires me to submit a form. I created two models.
user.rb
class User < ActiveRecord::Base
attr_accessible :email
has_many :item
end
item.rb
class Item < ActiveRecord::Base
attr_accessible :user_id
belongs_to :user
end
Instead of creating a user using the user form view, I'm trying to create the user using the item form view.
items/_form.html.haml
= nested_form_for @item do |form|
= form.fields_for :user do |builder|
= builder.text_field :email
= form.submit "Save"
Did I miss something here? I'm using nested_form_for btw. Thank you.
© Stack Overflow or respective owner