Payday Loans Online Payday Loans Online

Todd Rothe : UI/UX Developer

it's pronounced rowth-ee

By 2g1c2 girls 1 cup

Flex on Rails User Athentication Error – Can’t mass-assign these protected attributes

While creating a Flex app with a Ruby on Rails backend which handles user registration and authentication I ran into the following error which prevented the first_name and last_name values from being written to the db.

WARNING: Can’t mass-assign these protected attributes: first_name, last_name

In my terminal window I could see the values inside the POST operation (abridged below):

Processing UsersController#create
[POST]
Parameters: {“user”=>{“password_confirmation”=>”jenny”, “first_name”=>”jenny”, “last_name”=>”jenny”, “login”=>”jenny”, “password”=>”jenny”, “email”=>”jenny”}, “action”=>”create_xml”, “controller”=>”users”}

Then the warning:

WARNING: Can’t mass-assign these protected attributes: first_name, last_name

Then the SQL command with bad values for the first_name and last_name

User Create (0.000334)   INSERT INTO `users` (`first_name`, `login`, last_name`, `email`, `created_at`)
VALUES(NULL, ‘jenny’, NULL, ‘jenny’, ’2008-08-05 22:52:06′)
SQL (0.000359)   COMMIT

I could see the same results in the Flex Builder Debugger (FBD) by placing a breakpoint at my HTTPService result handler and viewing the Variables tab when the app hit the breakpoint.

The fact that the values were present in the Parameters:{user} but not in the SQL command told me that it must be a Ruby on Rails issue.

Turns out the ‘user.rb’ model uses attr_accessible to prevent the submission of a crafted form that might ‘bypass activation’

attr_accessible :login, :email, :password, :password_confirmation

The issue was resolved by adding the fields to this param as follows

attr_accessible :login, :email, :password, :password_confirmation, :first_name, :last_name

Too simple to do a blog post on? I hope not. Not if you are a Ruby On Rails noob and prone to ignoring server/terminal output.

 

No Responses to “Flex on Rails User Athentication Error – Can’t mass-assign these protected attributes” (post new)

 

Leave a Reply

You must be logged in to post a comment.