【问题标题】:Devise gem not deploying on Heroku platform设计 gem 未部署在 Heroku 平台上
【发布时间】:2014-07-04 18:05:42
【问题描述】:

花了 2 天时间尝试在 Heroku 上部署我的 Rails 应用程序后,我决定投降并在这里寻求帮助...

我的问题是我正在尝试在 Heroku 平台上部署 Rails 4.0.4 应用程序(它在我的本地环境中运行良好)但是当我尝试在 Heroku 平台上部署时它失败了。就像 Heroku 无法识别 Devise 3.2.4(或者不兼容)。

我总是收到相同的信息:

NoMethodError: undefined method `devise' for User (call 'User.connection' to establish 
a connection):Class

这里是命令git push heroku master的输出

[jeffersonlsz@localhost showYourselfApp (master)]$ git push heroku master
Enter passphrase for key '/home/jeffersonlsz/.ssh/id_rsa': 
X11 forwarding request failed on channel 0
Fetching repository, done.
Counting objects: 62, done.
Compressing objects: 100% (35/35), done.
Writing objects: 100% (36/36), 4.30 KiB, done.
Total 36 (delta 25), reused 0 (delta 0)

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.5.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Fetching gem metadata from https://rubygems.org/..........
       Fetching additional metadata from https://rubygems.org/..
       Using i18n (0.6.9)
       Using rake (10.3.1)
       Using minitest (4.7.5)
       Using multi_json (1.10.0)
       Using thread_safe (0.3.3)
       Using builder (3.1.4)
       Using erubis (2.7.0)
       Using tzinfo (0.3.39)
       Using rack (1.5.2)
       Using polyglot (0.3.4)
       Using mime-types (1.25.1)
       Using activerecord-deprecated_finders (1.0.3)
       Using arel (4.0.2)
       Using coffee-script-source (1.7.0)
       Using sass (3.2.19)
       Using execjs (2.0.2)
       Using thor (0.19.1)
       Using hike (1.2.3)
       Using json (1.8.1)
       Using pg (0.15.1)
       Using bundler (1.5.2)
       Using tilt (1.4.1)
       Using rails_serve_static_assets (0.0.2)
       Using rails_stdout_logging (0.0.3)
       Using activesupport (4.0.4)
       Using treetop (1.4.15)
       Using rack-test (0.6.2)
       Using coffee-script (2.2.0)
       Using rdoc (4.1.1)
       Using uglifier (2.5.0)
       Using bootstrap-sass (2.3.2.0)
       Using sprockets (2.11.0)
       Using rails_12factor (0.0.2)
       Using activemodel (4.0.4)
       Using jbuilder (1.5.3)
       Using actionpack (4.0.4)
       Using mail (2.5.4)
       Using sdoc (0.4.0)
       Using activerecord (4.0.4)
       Using railties (4.0.4)
       Using sprockets-rails (2.0.1)
       Using actionmailer (4.0.4)
       Using coffee-rails (4.0.1)
       Using jquery-rails (3.1.0)
       Using sass-rails (4.0.3)
       Using rails (4.0.4)
       Using turbolinks (2.2.2)
       Installing orm_adapter (0.5.0)
       Installing warden (1.2.3)
       Installing bcrypt (3.1.7)
       Installing devise (3.2.4)
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Bundle completed (12.69s)
       Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection):Class
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.4/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/app/models/user.rb:4:in `<class:User>'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/app/models/user.rb:1:in `<top (required)>'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:330:in `require_or_load'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:463:in `load_missing_constant'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:184:in `const_missing'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/inflector/methods.rb:226:in `const_get'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/inflector/methods.rb:226:in `block in constantize'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/inflector/methods.rb:224:in `each'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/inflector/methods.rb:224:in `inject'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/inflector/methods.rb:224:in `constantize'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:535:in `get'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:566:in `constantize'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise.rb:297:in `get'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/mapping.rb:77:in `to'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/mapping.rb:72:in `modules'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/mapping.rb:89:in `routes'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/mapping.rb:156:in `default_used_route'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/mapping.rb:66:in `initialize'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise.rb:331:in `new'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise.rb:331:in `add_mapping'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/rails/routes.rb:221:in `block in devise_for'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `each'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `devise_for'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/config/routes.rb:4:in `block in <top (required)>'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:335:in `instance_exec'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:335:in `eval_block'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:313:in `draw'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/config/routes.rb:1:in `<top (required)>'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `load'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `block in load'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `load'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/routes_reloader.rb:40:in `each'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/routes_reloader.rb:40:in `load_paths'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/routes_reloader.rb:16:in `reload!'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/routes_reloader.rb:26:in `block in updater'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/file_update_checker.rb:75:in `call'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/file_update_checker.rb:75:in `execute'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/routes_reloader.rb:27:in `updater'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/initializable.rb:30:in `run'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/initializable.rb:54:in `run_initializers'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application.rb:215:in `initialize!'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/railtie/configurable.rb:30:in `method_missing'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/config/environment.rb:5:in `<top (required)>'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application.rb:189:in `require_environment!'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application.rb:250:in `block in run_tasks_blocks'
       /tmp/build_59a23f0f-d0e9-44ae-8fb5-c417d3b22c35/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/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 app

To git@heroku.com:gentle-escarpment-8370.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:gentle-escarpment-8370.git'

这是我的Gemfile

source 'https://rubygems.org'


gem 'rails', '4.0.4'

gem 'bootstrap-sass', '2.3.2.0'
gem 'sprockets', '2.11.0'
gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
  gem 'sdoc', require: false
end

gem 'devise'
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'

最后,我的User 模特:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_many :experiences
end

我不是一位经验丰富的 Ruby 或 Rails 开发人员(我研究该框架不到两个月),但我怀疑 Heroku 平台与 Rails 4.0.4 或 Devise 3.2.4 不兼容。

有什么建议吗?

【问题讨论】:

  • Rails 和你拥有的设计版本都应该使用heroku。这是别的东西
  • 我使用相同版本的 devise 和 rails 部署了应用程序,没有任何问题。尝试在本地机器上运行 rake assets:precompile,看看是否无法编译具有相同错误的资产?
  • 是的,做 rake assets:precompile 然后推送到 github repo,然后再推送到 heroku master
  • 这就是问题所在。命令 rake assets:precompile 在我的机器上运行良好。但是当我尝试在 Heroku 上部署时,它就不起作用了。
  • 运行heroku run rake db:migrate

标签: ruby-on-rails ruby heroku ruby-on-rails-4 devise


【解决方案1】:

您是否运行过deviseinstaller? This question 似乎认为您的应用中没有devise initializer

根据Devise installation docs,你这样做了吗:

rails generate devise:install

如果您查看错误将是什么,这似乎可以得到证实:

devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

这是在 user 模型中 - 这意味着您得到的错误是因为这条线。 undefined method 错误意味着您尚未加载应用程序的该部分,因为未安装依赖项 (gem),或者您尚未对其进行初始化

你能确认你有config/initializers/devise.rb在场吗?

【讨论】:

    【解决方案2】:

    我假设您已经解决了问题,但以防万一您还没有,这可能会有所帮助。我有同样的问题,我的问题是我在 .gitignore 中有 ./config/initializers/devise.rb 文件。您可以尝试更新此文件以解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 2011-02-18
      相关资源
      最近更新 更多