切换到Rails 4.1时的错误 - `method_missing':未定义的方法`whitelist_attributes ='表示ActiveRecord :: Base:Class(NoMethodError)

 机敏的柑桔hs5 发布于 2022-12-04 15:38

从Rails 4.0切换到Rails 4.1时,我收到此错误:

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:

配置/ application.rb中:

config.active_record.whitelist_attributes = false

完整的错误日志是:

/home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/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/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activerecord-4.1.8/lib/active_record/railtie.rb:110:in `block (3 levels) in '
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activerecord-4.1.8/lib/active_record/railtie.rb:109:in `each'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activerecord-4.1.8/lib/active_record/railtie.rb:109:in `block (2 levels) in '
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `each'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activerecord-4.1.8/lib/active_record/railtie.rb:108:in `block in '
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/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/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `public_send'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `method_missing'
    from /home/mathieu/rails_projects/app/config/environment.rb:5:in `'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/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 
' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/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 `
' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/gems/rack-1.5.2/lib/rack/server.rb:199:in `app' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands/server.rb:50:in `app' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@global/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands/server.rb:130:in `log_to_stdout' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands/server.rb:67:in `start' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:81:in `block in server' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `tap' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:76:in `server' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!' from /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/railties-4.1.8/lib/rails/commands.rb:17:in `' from bin/rails:4:in `require' from bin/rails:4:in `
'

我真的迷失在这里,因为大多数人都有与我有关的bug建议使用gem'en protected_attributes but I don't want to use it as I don't have anyattr_accessible norattr_protected`.

知道这个bug来自哪里?

1 个回答
  • 您可以安全地删除 config.active_record.whitelist_attributes = false

    从您的应用配置文件.

    并删除模型类中的所有white_list_attributes.

    干杯,

    2022-12-11 02:12 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有