【问题标题】:Ruby on rails: rake is not workingRuby on rails:rake 不工作
【发布时间】:2015-07-14 02:53:25
【问题描述】:

当我尝试在我的 Rails 中运行任何 rake 测试时,它会给我错误消息“未定义的方法 `whitelist_attributes”。我不知道它为什么会来。

我得到的错误是:


    NoMethodError: undefined method `whitelist_attributes=' for #  <Class:0x50de7d8>
  C:/Users/Arvind/project/book/config/initializers/devise.rb:21:in `block in <top (required)>'
 C:/Users/Arvind/project/book/config/initializers/devise.rb:4:in `<top (required)>'
 C:/Users/Arvind/project/book/config/environment.rb:8:in `<top (required)>'
     Tasks: TOP => environment
    (See full trace by running task with --trace)`enter code here`

我的 gem 文件如下所示:


  source 'https://rubygems.org'


   # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
   gem 'rails', '4.2.1'
  # Use sqlite3 as the database for Active Record

   gem 'devise'
  gem 'protected_attributes'


  gem 'simple_form'
  gem 'state_machine', :git => 'https://github.com/seuros/state_machine.git'
  gem 'draper', '~> 2.1'
  gem 'js-routes'
  gem 'paperclip', :git => "git://github.com/thoughtbot/paperclip.git"
  gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-    bootstrap-rails.git'
  gem 'will_paginate'
 gem 'bootstrap-will_paginate'
 gem 'private_pub'
 gem 'foreman'
 gem 'bootstrap-sass', :git => 'git://github.com/thomas-mcdonald/bootstrap-sass.git'
 gem 'font-awesome-less'
  gem 'faye'
   group :development do
   gem 'thin'
    end
  group :test do
    gem 'shoulda'
    gem 'factory_girl_rails'
    end

  group :development do
   gem 'sqlite3'
    gem 'log_buddy'
 end

  group :production do
     gem 'pg'
  end
    gem 'rails_12factor', group: :production

     gem 'sass-rails', '~> 5.0'
   # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
 # Use CoffeeScript for .coffee assets and views
   gem 'coffee-rails', '~> 4.1.0'
   # See https://github.com/rails/execjs#readme for more supported runtimes
   # gem 'therubyracer', platforms: :ruby

  # Use jquery as the JavaScript library
    gem 'jquery-rails'
 # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
  gem 'turbolinks'
 # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
  # bundle exec rake doc:rails generates the API under doc/api.
 gem 'sdoc', '~> 0.4.0', group: :doc

  # Use ActiveModel has_secure_password
    # gem 'bcrypt', '~> 3.1.7'

 # Use Unicorn as the app server
 # gem 'unicorn'

 # Use Capistrano for deployment
 # gem 'capistrano-rails', group: :development

  group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger  console
   gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
   gem 'web-console', '~> 2.0'
end

   # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby gem asset-pipeline


    【解决方案1】:

    您的config/application.rb 文件中是否定义了config.active_record.whitelist_attributes?如果是这样,请删除该行或将其设置为 false:config.active_record.whitelist_attributes = false

    您的模型类中是否定义了white_list_attributes?如果是这样,请删除这些。您应该在 4.2.1 中使用 strong_parameters。 https://github.com/rails/strong_parameters

    【讨论】:

    • 我从我的 config/application.rb 中删除了“config.active_record.whitelist_attributes”。但没有任何“white_list_attributes”。仍然给出同样的错误
    • 现在安装 Strong_parameters 后我收到此错误:- rake db:reset rake aborted! NameError: uninitialized constant ActiveModel::ForbiddenAttributesProtection C:/Users/Arvind/project/book/config/application.rb:10:in &lt;top (required)&gt;' C:/Users/Arvind/project/book/Rakefile:4:in ' (通过使用 --trace 运行任务查看完整跟踪)
    • heroku run rake db:setup Running rake db:setup 附加到终端... up, run.6684 致命:数据库“postgres”权限被拒绝 详细信息:用户没有 CONNECT 权限。 /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in initialize'........ NoMethodError: undefined method whitelist_attributes=' for ActiveRecord::Base:Class
    • 嗯...您可能需要将其设置为 false。可能需要查看您的配置文件以查看您在其中打开此功能的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 2014-01-05
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 2015-12-25
    相关资源
    最近更新 更多