dirkava (10) [Avatar] Offline
I got the following error even after adjusting my user_steps.rb

Can't mass-assign protected attributes: admin (ActiveModel::MassAssignmentSecurity::Error)
./features/step_definitions/user_steps.rb:4:in `block (2 levels) in <top (required)>'
./features/step_definitions/user_steps.rb:2:in `each'
./features/step_definitions/user_steps.rb:2:in `/^there are the following users:$/'
features/creating_projects.feature:7:in `Given there are the following users:'


Given /^there are the following users:$/ do |table|
table.hashes.each do |attributes|
unconfirmed = attributes.delete("unconfirmed") == "true"
@user = User.create!(attributes)
@user.update_attribute("admin", attributes["admin"] == "true")
@user.confirm! unless unconfirmed

My cucumber background feature:


Given there are the following users:
| email | password | admin |
| admin@ticketee.com | password | true |
And I am signed in as them
Given I am on the homepage
When I follow "New Project"


Anyone knows what's going on? The books tells me that after implementing a line in user_steps.rb this error should be prevented.. smilie

Many thanks!
Kindest regards,
ryanbigg (423) [Avatar] Offline
Re: Chapter 7.1 Can't mass-assign protected attributes error
The admin attribute must also be deleted from the attributes hash before create is called. Something like this:

admin = attributes.delete("admin")

@user.update_attribute("admin", admin == "true")

You will probably run into this kind of issue more often as you go through the book because you have chosen to use a more recent version of Rails.
dirkava (10) [Avatar] Offline
Re: Chapter 7.1 Can't mass-assign protected attributes error
Thanks Ryan!

Could you give me some advise about which version of Rails I should use to make it suitable for the book?

And how to downgrade my rails (since there seems to be different ways on the internet).