簡體   English   中英

無法將Rails應用程序部署到heroku

[英]unable to deploy rails app to heroku

我的Rails應用程序可以在Mac上的開發模式下工作。 我嘗試將其編譯為heroku時,在命令行中出現錯誤

    Cleaning up the bundler cache.
           Removing bundler (1.3.2)
    -----> Writing config/database.yml to read from DATABASE_URL
    -----> Preparing app for Rails asset pipeline
           Running: rake assets:precompile
           rake aborted!
           undefined method `[]' for nil:NilClass
           /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/config/initializers/devise.rb:234:in `block in <top (required)>'
           /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/vendor/bundle/ruby/2.0.0/gems/devise-3.1.2/lib/devise.rb:276:in `setup'
           /
           /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0.rc1/lib/rails/engine.rb:609:in `bl
     /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application.rb:214:in `initialize!'
       /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0.rc1/lib/rails/railtie/configurable.rb:30:in `method_missing'
       /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/config/environment.rb:5:in `<top (required)>'
       /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0.rc1/lib/active_support/dependencies.rb:228:in `require'
       /tmp/build_9afd2a8f-0be9-427c-82f9-5431cf3a30fc/vendor/bundle/ruby/2.0.0/gems/activesupport-
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

 !     Push rejected, failed to compile Ruby app

檢查了我的devise.rb我唯一添加的行是

config.omniauth :facebook, FACEBOOK_CONFIG['facebook_api_key'], FACEBOOK_CONFIG['facebook_api_secret'], scope: "email, publish_actions"

and this is my gemfile - as you can see i have the production and development information included


group :development, :test do
     gem 'sqlite3'
end

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

根據建議設計230-238

# ==> OmniAuth
  # Add a new OmniAuth provider. Check the wiki for more information on setting
  # up on your models and hooks.
   config.omniauth :facebook, FACEBOOK_CONFIG['facebook_api_key'], FACEBOOK_CONFIG['facebook_api_secret'], scope: "email, publish_actions"

  # ==> Warden configuration
  # If you want to use other strategies, that are not supported by Devise, or
  # change the failure app, you can configure them inside the config.warden block.

您可能想停止使用此magick FACEBOOK_CONFIG變量,並開始將環境變量用於heroku

config.omniauth :facebook, ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_API_SECRET'], scope: "email, publish_actions"

為了使該ENV可以更輕松地進行開發,請檢查: https : //github.com/bkeepers/dotenvhttps://github.com/laserlemon/figaro

顯然,您要使用的FACEBOOK_CONFIGnil

首先,您必須在Heroku帳戶中設置兩個環境變量

$ heroku config:set FACEBOOK_API_KEY=your-key-here
$ heroku config:set FACEBOOK_API_SECRET=your-secret-here

然后驗證這些設置是否正確:

$ heroku config:get FACEBOOK_API_KEY
$ heroku config:get FACEBOOK_API_SECRET

最后,如下更新device.rb文件:

config.omniauth :facebook, ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_API_SECRET'], scope: "email, publish_actions"

現在應該很好。

看來問題出在Devise。 錯誤說

undefined method `[]' for nil:NilClass 

如果您查看下一行,它來自哪里。

config/initializers/devise.rb:234

因此,錯誤位於config / initializers / devise.rb中的第234行。

在Mac上運行以下命令。

bundle exec rake assets:precompile

如果沒有得到相同的錯誤,則說明您的生產環境存在問題。

您可以在config / initializers / devise.rb:234上添加您的內容嗎

只需使用相同的信息更新您的facebook.yml文件即可進行生產。 我想你只有發展。

/config/facebook.yml

development:
  facebook_api_key: copy_from_here
  facebook_api_secret: copy_2_from_here

production:
  facebook_api_key: paste_to_here
  facebook_api_secret: paste_2_here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM