26

I'm learning Rails with the awesome Ruby on Rails Tutorial by Michael Hartl. I'm on section 3.2.2 (Test Driven Development) in which I need to run the following command to run the rspec tests for my Rails project:

bundle exec rspec spec/

But it doesn't work. Instead I get this error:

/Users/mh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/
activerecord-3.1.3/lib/active_record/base.rb:1088:in `method_missing':
undefined method `mass_assignment_sanitizer=' for
ActiveRecord::Base:Class (NoMethodError)

I've tried reinstalling rspec and changing my Gemfile, but nothing appeases the undefined method error!

5
  • Oh, also, when I try to run rspec spec/ I get a command not found error.
    – hao_maike
    Commented Dec 27, 2011 at 16:49
  • try without trailing slash. rspec spec. (just thinking) Commented Dec 27, 2011 at 16:51
  • Unfortunately I still get the same error without the slash.
    – hao_maike
    Commented Dec 27, 2011 at 16:54
  • What if you put config.active_record.mass_assignment_sanitizer = :strict in config/enviroments/test.rb? Are you using rails2?
    – Fenec
    Commented Dec 27, 2011 at 17:03
  • I'm using rails 3.1. I added the line of code but still get the error.
    – hao_maike
    Commented Dec 27, 2011 at 17:11

2 Answers 2

76

Did you downgrade from Rails 3.2 RC1? Comment out the following two lines from your development.rb:

config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
3
  • This worked perfectly for me after downgrading from 3.2 to 3.1.2!
    – Dan Higham
    Commented Mar 22, 2012 at 10:56
  • 2
    since TS using rspec , he should be commenting out the line in test.rb instead of development.rb Commented Aug 3, 2012 at 3:42
  • 3
    Had this same problem and fix when upgrading from Rails 3.2 to 4.2 Commented Dec 12, 2015 at 23:29
1

While m818's answer will solve the problem, you might still get errors if you are tyring to use deprecated methods elsewhere in your code.

I had the same problem, commenting out those lines got rid of some errors, but not all of them, anywhere I was using attr_accessible gave me the same error.

It turned out to be the `active_record' gem that was updated to 4.0 when I didn't want it to. Since I'm using a Padrino app, I had to do this in the Gemfile:

gem 'activerecord', '= 3.2.12', :require => "active_record"

That solved all issues and I didn't have to comment out the lines in database.rb.

Not the answer you're looking for? Browse other questions tagged or ask your own question.