2

我已将代码中的所有 attr_accessible 更改为强参数,因此它适用于 Rails 4.0。我的应用程序在本地运行良好,但是当我推送到 Heroku 时,它抱怨我的代码中有 attr_accessible。这是我得到的错误:

   Running: rake assets:precompile
   rake aborted!
   `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one.
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activemodel-4.0.0/lib/active_model/deprecated_mass_assignment_security.rb:14:in `attr_accessible'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/lib/redactor-rails/orm/active_record.rb:20:in `block in extended'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/lib/redactor-rails/orm/active_record.rb:14:in `class_eval'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/lib/redactor-rails/orm/active_record.rb:14:in `extended'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/lib/redactor-rails/orm/active_record.rb:9:in `extend'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/lib/redactor-rails/orm/active_record.rb:9:in `included'
   /tmp/build_12jc2ej0437ky/app/models/redactor_rails/asset.rb:20:in `include'
   /tmp/build_12jc2ej0437ky/app/models/redactor_rails/asset.rb:20:in `<class:Asset>'
   /tmp/build_12jc2ej0437ky/app/models/redactor_rails/asset.rb:19:in `<top (required)>'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:329:in `require_or_load'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:462:in `load_missing_constant'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:183:in `const_missing'
   /tmp/build_12jc2ej0437ky/app/models/redactor_rails/document.rb:1:in `<top (required)>'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:329:in `require_or_load'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:462:in `load_missing_constant'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:183:in `const_missing'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/lib/redactor-rails.rb:31:in `document_model'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/app/controller/redactor_rails/documents_controller.rb:2:in `<class:DocumentsController>'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/redactor-rails-0.3.5/app/controller/redactor_rails/documents_controller.rb:1:in `<top (required)>'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:329:in `require_or_load'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:288:in `depend_on'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:206:in `require_dependency'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `each'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `block in eager_load!'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `each'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `eager_load!'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:347:in `eager_load!'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `each'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
   /tmp/build_12jc2ej0437ky/config/environment.rb:5:in `<top (required)>'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'
   /tmp/build_12jc2ej0437ky/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.0/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'
   Tasks: TOP => environment
   (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

 !     Push rejected, failed to compile Ruby/Rails app

To git@heroku.com:scratch-cms.git
 ! [remote rejected] master -> master (pre-receive hook declined)

关于发生了什么的任何想法?会不会是宝石?可能是设计?

4

4 回答 4

2

我认为你是对的,这是因为设计。这是因为在 rails-4 中,ActiveModel::MassAssignmentSecurity 已从 ActiveModel 中取出。但是设计使用 attr_accessible,因此要使用它,只需在您的 Gemfile 中添加以下 gem 并尝试再次加载。

gem 'protected_attributes'

现在设计支持rails-4。试试这个设计版本它会帮助你

gem 'devise', '3.0.0.rc'

编辑: 然后我会建议你使用这个链接它给你一些想法。

于 2013-07-30T06:53:51.893 回答
0

同样的问题。我是这样解决的

gem 'protected_attributes'
gem 'devise'
gem 'responders',          github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack',             github: 'ernie/ransack',            branch: 'rails-4'
gem 'activeadmin',         github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic',          github: 'justinfrench/formtastic'
于 2013-07-30T06:56:42.017 回答
0

如我所见,有两个问题->

1.) 在您的 Gemfile 中包含资产服务

# static asset serving and logging on Heroku
gem 'rails_12factor', group: :production

2.)将您使用的任何属性添加到您的application_controller.rb

devise_parameter_sanitizer.for(:account_update) do |u|
        u.permit(:name, :email, :password, :current_password, :password_confirmation,
                         :avatar, :firstname, :lastname, :userbio, :country, :gender)
    end

看看我的 Application_Controller ->这里

删除模型中可访问的 Attr。

于 2013-07-30T07:06:11.653 回答
0

我解决了我的问题。有问题的宝石是redactor。0.3.5 版本使用了 attr_accessible,而 0.4 版本没有。一旦我更改了 Gemfile 中的版本,一切就正常了。

于 2013-08-11T18:44:10.593 回答