2015-03-03 56 views
1

我目前在嘗試升級一個Rails 3.2的應用程序我Gemfile通過引用的Rails的正確版本到Rails 4.我更新:從Rails 3.2升級到Rails 4時,爲什麼Rake會給'未初始化的常量ActiveModel :: ForbiddenAttributesProtection'?

gem 'rails', '~>4.0.0' 

以及去除assets頭,每here

接下來,我試圖運行rake rails:update。它給了我這個錯誤:

rake aborted! 
NameError: uninitialized constant ActiveModel::ForbiddenAttributesProtection 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:6:in `<module:AttributeAssignment>' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:3:in `<module:ActiveRecord>' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:2:in `<top (required)>' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:300:in `<class:Base>' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:281:in `<module:ActiveRecord>' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:22:in `<top (required)>' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/railtie.rb:38:in `block in <class:Railtie>' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `instance_exec' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `block in run_tasks_blocks' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `each' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `run_tasks_blocks' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `block in run_tasks_blocks' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `run_tasks_blocks' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine.rb:446:in `load_tasks' 
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie/configurable.rb:30:in `method_missing' 
/vagrant/Rakefile:7:in `<top (required)>' 
(See full trace by running task with --trace) 

什麼是造成這個錯誤?

回答

4

我能在網上找到這個錯誤的唯一地方是this GitHub issue

我在該頁面上搜索了ActiveModel::ForbiddenAttributesProtection,發現它在here

正如我讀的是評論和之後,我發現this one,其中說:

Rails 3.2 apps can just add strong_parameter gem AFAIK and it would work out of the box.

看着我Gemfile我再次意識到了什麼問題。它包含這行:

gem 'strong_parameters' 

的問題是,strong_parameters寶石複製鋼軌4做事,讓新的方式,在Rails的3.2可以使用更好的代碼。因此,它與Rails 4中的內置功能衝突。

我從我的Gemfile中刪除了該行,並且在運行bundle後,rake命令起作用。

編輯:重新啓動unicorn後,我得到了類似的日誌錯誤。我刪除config/initializers/strong_parameters.rb,但這似乎沒有幫助。但是,重啓我的虛擬機之後,它正常運行。

相關問題