oprogfrogo
oprogfrogo

Reputation: 2074

Rails 3.2 Undefined method error for active_record/mass_assignment_sanitizer

I upgraded rails from 3.1 to 3.2 and added the following inside my environments/development.rb file:

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5

Adding that returns this error when trying to start server:

/User/oprogfrogo/.rvm/gems/ruby-1.9.2-p180@rails32/gems/railties-3.2.0/lib/rails/railtie
/configuration.rb:85:in `method_missing': undefined method `active_record' for 
#<Rails::Application::Configuration:0x00000101305e88> (NoMethodError)

When I remove it, all is fine. Why is this happening?

Upvotes: 2

Views: 3542

Answers (2)

oprogfrogo
oprogfrogo

Reputation: 2074

I found the problem. My app was setup initially to exclude active records and just be a non-database backed app.

Upvotes: 3

Mattias Wadman
Mattias Wadman

Reputation: 11425

Weird, but take a look at the method_missing method in lib/rails/railtie/configuration.rb.

def method_missing(name, *args, &blk)
  puts "in configuration.rb:method_missing" # <= try to add these debug lines
  puts name
  puts args
  if name.to_s =~ /=$/
      @@options[$`.to_sym] = args.first
  elsif @@options.key?(name)
    @@options[name]
  else
    super # <= 85 line
  end
end

I would guess that the name.to_s =~ /=$/ is what should be true but isn't, it checks for a method ending with =. Try to add some debug log at the beginning of the method and see if you might i.e. have accidently included some weird characters in the config variable name.

Upvotes: 0

Related Questions