2014-12-18 33 views
14

當從滑軌4.0切換到4.1的Rails我正在此錯誤:錯誤切換到Rails 4.1時 - `的method_missing ':未定義的方法`whitelist_attributes =' ActiveRecord的::基地:類(NoMethodError)

activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `whitelist_attributes=' for ActiveRecord::Base:Class (NoMethodError) 

我沒有在我的應用程序的任何地方使用attr_accessibleattr_protected,所以我不知道爲什麼我有問題。

當移動到Rails 4.0,我已經把我的application.rb中:

的config/application.rb中:

config.active_record.whitelist_attributes = false 

完整的錯誤日誌:

/home/mathieu/.rvm/gems/[email protected]/gems/activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `whitelist_attributes=' for ActiveRecord::Base:Class (NoMethodError) 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activerecord-4.1.8/lib/active_record/railtie.rb:110:in `block (3 levels) in <class:Railtie>' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activerecord-4.1.8/lib/active_record/railtie.rb:109:in `each' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activerecord-4.1.8/lib/active_record/railtie.rb:109:in `block (2 levels) in <class:Railtie>' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `each' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `on_load' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activerecord-4.1.8/lib/active_record/railtie.rb:108:in `block in <class:Railtie>' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/initializable.rb:55:in `block in run_initializers' 
    from /home/mathieu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each' 
    from /home/mathieu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component' 
    from /home/mathieu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from' 
    from /home/mathieu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component' 
    from /home/mathieu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each' 
    from /home/mathieu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component' 
    from /home/mathieu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `public_send' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `method_missing' 
    from /home/mathieu/rails_projects/app/config/environment.rb:5:in `<top (required)>' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require' 
    from /home/mathieu/rails_projects/_app/config.ru:3:in `block in <main>' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize' 
    from /home/mathieu/rails_projects/app/config.ru:in `new' 
    from /home/mathieu/rails_projects/app/config.ru:in `<main>' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/server.rb:199:in `app' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands/server.rb:50:in `app' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands/server.rb:130:in `log_to_stdout' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands/server.rb:67:in `start' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:81:in `block in server' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `tap' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `server' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!' 
    from /home/mathieu/.rvm/gems/[email protected]/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 

我我真的失去了這裏,因爲大多數有漏洞的人都建議使用gem'protected_attributes but I don't want to use it as I don't have any attr_accessible nor attr_protected`。

任何想法,這個錯誤來自哪裏?

+1

Rails 4使用strong_params而不是attr_accessible。閱讀如何升級http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html – cristian 2014-12-18 22:59:10

+0

刪除配置設置「whitelist_attributes」。 – 2014-12-18 23:28:37

+0

我有同樣類型的問題,但不同的錯誤,請你檢查以下鏈接 http://stackoverflow.com/questions/29227079/issues-with-rails4-and-mongoid-on-production-mode – ratnakar 2015-03-26 09:33:25

回答

28

您可以安全地刪除 config.active_record.whitelist_attributes =假

從您的應用程序配置文件。

並刪除模型類中的所有white_list_attributes。

乾杯,

+5

也,我們可能必須從development.rb刪除config.active_record.mass_assignment_sanitizer =:strict – 2015-06-13 08:20:49

+0

也適用於'config.active_record.whitelist_attributes = true'嗎?因爲我得到同樣的錯誤。 – FedericoCapaldo 2017-03-12 05:45:09

相關問題