rails / protected_attributes

Protect attributes from mass-assignment in ActiveRecord models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uninitialized constant ActiveRecord::MassAssignmentSecurity

briarsweetbriar opened this issue · comments

On an upgrade from Rails 3.2, I get the following error when I start the rails server:

C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/protected_attributes-0.0.1/
lib/active_record/mass_assignment_security/attribute_assignment.rb:35:in `initia
lize_mass_assignment_sanitizer': uninitialized constant ActiveRecord::MassAssign
mentSecurity::AttributeAssignment::ClassMethods::Model (NameError)
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/protected_attr
ibutes-0.0.1/lib/active_record/mass_assignment_security/attribute_assignment.rb:
16:in `block in <module:AttributeAssignment>'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/rails-
daa7b4e2f0f0/activesupport/lib/active_support/concern.rb:114:in `class_eval'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/rails-
daa7b4e2f0f0/activesupport/lib/active_support/concern.rb:114:in `append_features
'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/protected_attr
ibutes-0.0.1/lib/active_record/mass_assignment_security.rb:14:in `include'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/protected_attr
ibutes-0.0.1/lib/active_record/mass_assignment_security.rb:14:in `<class:Base>'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/protected_attr
ibutes-0.0.1/lib/active_record/mass_assignment_security.rb:12:in `<top (required
)>'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/protected_attr
ibutes-0.0.1/lib/protected_attributes.rb:3:in `<top (required)>'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.2.2/
lib/bundler/runtime.rb:68:in `require'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.2.2/
lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.2.2/
lib/bundler/runtime.rb:66:in `each'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.2.2/
lib/bundler/runtime.rb:66:in `block in require'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.2.2/
lib/bundler/runtime.rb:55:in `each'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.2.2/
lib/bundler/runtime.rb:55:in `require'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-1.2.2/
lib/bundler.rb:128:in `require'
    from C:/Sites/shelflives/config/application.rb:7:in `<top (required)>'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/rails-
daa7b4e2f0f0/railties/lib/rails/commands.rb:83:in `require'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/rails-
daa7b4e2f0f0/railties/lib/rails/commands.rb:83:in `block in <top (required)>'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/rails-
daa7b4e2f0f0/railties/lib/rails/commands.rb:80:in `tap'
    from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/rails-
daa7b4e2f0f0/railties/lib/rails/commands.rb:80:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I'm not sure why this is happening, but on a lark I deleted the contents the method that was throwing the error:

    def initialize_mass_assignment_sanitizer
      attr_accessible(nil) if Model.whitelist_attributes
      self.mass_assignment_sanitizer = Model.mass_assignment_sanitizer if Model.mass_assignment_sanitizer
    end

The server will boot up after that, but when I try actually assigning values, I get a "stack level too deep" error. Any idea what's going on?

Can you test to see whether you get the same problem using this in your Gemfile:

gem 'protected_attributes', :github => 'rails/protected_attributes'

the gem version you're using is out of date.

That did the trick. Thanks for the quick reply!