12 Jun 2013, 22:52
Generic-user-small

Richard Wilson (6 posts)

I have been littering stack overflow with quetsions trying to get the books code to work with Rails 3.2 I’m using the fourth edition. Apparently it was designed to work before these MassAssignment security warnings. Now I’m stuck at the following:

# Running tests:

[21/32] OrdersControllerTest#test_should_get_new = 0.00 s                             
  1) Error:
test_should_get_new(OrdersControllerTest):
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: cart
    /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
    /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
    /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
    /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'

I have no idea where to put the attr_accessible token for cart and really feel like giving up now. It took me a good while to figure out the previous mass assignment warnings too.

Hell, even jQuery was a nightmare to get working with rails..

Please advise :/

13 Jun 2013, 01:27
Samr_small_pragsmall

Sam Ruby (584 posts)

Can you tell me which edition you have? For starters, what does it say in the top right hand corner of the cover? (i.e., does it have a triangle, and if so, what is in that triangle).

Then can you read me the last two lines of page vi (roman numeral 6)? It should say something like Px.y Printing month, year; then Version year-month-day.

13 Jun 2013, 20:43
Generic-user-small

Richard Wilson (6 posts)

In the triangle it says Rails 3.2

Book version: P2.2—January 2012

vi is the contents…

13 Jun 2013, 20:43
Generic-user-small

Richard Wilson (6 posts)

➜ ~ rails -v Rails 3.2.13

(rails version)

15 Jun 2013, 19:14
Samr_small_pragsmall

Sam Ruby (584 posts)

P2.2 was based on Rails 3.2.0. The mass assignment changes were introduced in Rails 3.2.3. For what it is worth, the mass assignment changes were removed in Rails 4.0 and strong parameters was added.

It is indeed hard to learn a framework as big as Rails when you are using a version different than the one covered by the book. At this point, I would recommend following the instructions in section 1.4:

gem install rails --version 3.2.0
rails __3.2.0__ new depot
17 Jun 2013, 05:12
Generic-user-small

Richard Wilson (6 posts)

Thanks sam, this fixed it. Yeah, Mass Assignment is a little silly, I mean I understand why its needed, but still.

I have another question, but its suited for another topic.

  You must be logged in to comment