10 Apr 2013, 15:06
Generic-user-small

Louis Rhys (22 posts)

My functional tests of D3 failed with the above message. Any idea what I did wrong here?

ERROR (0:00:00.202) should create line item
          Can't mass-assign protected attributes: product
        @ /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/base.rb:498:in `initialize'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/reflection.rb:183:in `new'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/reflection.rb:183:in `build_association'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:233:in `build_record'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/associations/collection_association.rb:112:in `build'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/associations/collection_proxy.rb:46:in `build'
          app/controllers/line_items_controller.rb:45:in `create'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:167:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/rendering.rb:10:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:414:in `_run__1025548117__process_action__122448650__callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:17:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/rescue.rb:29:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:475:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:49:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:397:in `post'
          test/functional/line_items_controller_test.rb:21:in `block (2 levels) in <class:LineItemsControllerTest>'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/testing/assertions.rb:55:in `assert_difference'
          test/functional/line_items_controller_test.rb:20:in `block in <class:LineItemsControllerTest>'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:469:in `_run__187006020__setup__1029918633__callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

     PASS (0:00:00.209) should destroy line item
     PASS (0:00:00.216) should get edit
     PASS (0:00:00.221) should get index
     PASS (0:00:00.227) should get new
     PASS (0:00:00.232) should show line item
    ERROR (0:00:00.235) should update line item
          Can't mass-assign protected attributes: cart_id, product_id
        @ /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.13/lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/persistence.rb:216:in `block in update_attributes'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in `transaction'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/persistence.rb:215:in `update_attributes'
          app/controllers/line_items_controller.rb:64:in `block in update'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/mime_responds.rb:270:in `call'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/mime_responds.rb:270:in `retrieve_collector_from_mimes'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/mime_responds.rb:194:in `respond_to'
          app/controllers/line_items_controller.rb:63:in `update'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:167:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/rendering.rb:10:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:414:in `_run__1025548117__process_action__701424849__callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:17:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/rescue.rb:29:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:475:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:49:in `process'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:402:in `put'
          test/functional/line_items_controller_test.rb:38:in `block in <class:LineItemsControllerTest>'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:469:in `_run__187006020__setup__1029918633__callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
          /home/user/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
10 Apr 2013, 15:33
Generic-user-small

Louis Rhys (22 posts)

My Rails version is 3.2.13. It seems to be related. Any idea how to fix it without changing rails version?

10 Apr 2013, 16:38
Samr_small_pragsmall

Sam Ruby (584 posts)

Rails changed in a major way in this area between Rails 3.2 and Rails 4.0. That’s why we make available editions tailed for specific versions of Rails:

  • http://pragprog.com/book/rails32/agile-web-development-with-rails-3-2
  • http://pragprog.com/book/rails4/agile-web-development-with-rails

That being said, the Rails team has made the functionality you need available as a migration aide: https://github.com/rails/strong_parameters/blob/master/README.md

Also, the code you can download from http://pragprog.com/titles/rails4/source_code has a rails32 directory.

One final resource: http://intertwingly.net/projects/dashboard.html shows how the current version of the book needs to be adapted to support different versions of Ruby and Rails.

11 Apr 2013, 14:08
Generic-user-small

Louis Rhys (22 posts)

How many editions are there? My book says “Fourth Edition” but also says “For Rails 3.1”

11 Apr 2013, 16:56
Samr_small_pragsmall

Sam Ruby (584 posts)

There have been six printings to date of the fourth edition. Some of them merely address reader feedback. A few of them address substantial changes in Rails itself. In the latter case, the cover is updated to indicate which version of Rails is covered.

Given the number of people who have, as you did, got stuck after choosing to try a different version of Rails than the one that their printing targets, I’m made the advice successively stronger in more recent printings to stick with the version that is known to work with the book.

If you do wish to proceed with 3.2.13 with the printing you have, add an attr_accessible line to your model as described in http://theengguy.blogspot.com/2012/05/dealing-with-cant-mass-assign-protected.html

  You must be logged in to comment