设计gem不在Heroku平台上部署

时间:2014-05-16 04:34:37

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

在尝试在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不兼容。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

您是否运行过devise安装程序? 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在场?

答案 1 :(得分:0)

我认为你已经解决了问题但是如果你没有解决问题,这可能会有所帮助。我有同样的问题,我的问题是我在.gitignore中有./config/initializers/devise.rb文件。您可以尝试更新此文件以解决问题。