Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method `mass_assignment_sanitizer=' for ActiveRecord::Base:Class (NoMethodError)

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!

like image 599
hao_maike Avatar asked Dec 27 '11 16:12

hao_maike


2 Answers

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 
like image 58
m818 Avatar answered Sep 24 '22 07:09

m818


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.

like image 42
kakubei Avatar answered Sep 24 '22 07:09

kakubei