Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails attr_protected

I have the following code in my User model:

attr_protected :email

I'm trying to create a new user object, but I get a mass assignment protected error with the following code.

user = User.new(
    :first_name => signup.first_name,
    :last_name => signup.last_name,
    :email => signup.email,
    :birthday => signup.birthday,
    :encrypted_password => signup.encrypted_password,
    :salt => signup.salt
  )

Does anyone know how I can work around the attr_protected to get this code to work and assign a value to email?

Thank you.

like image 732
Brian Avatar asked Dec 05 '25 15:12

Brian


1 Answers

user = User.new(
  :first_name => signup.first_name,
  :last_name => signup.last_name,
  :birthday => signup.birthday,
  :encrypted_password => signup.encrypted_password,
  :salt => signup.salt
)
user.email = signup.email
like image 197
yfeldblum Avatar answered Dec 07 '25 03:12

yfeldblum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!