Rails - 设计/ Omniauth - 无方法错误配置

时间:2014-07-22 04:19:50

标签: ruby-on-rails facebook heroku devise omniauth

我试图将facebook身份验证与设计集成。

我使用了本教程(http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin)并让它在本地工作,但是当我推送到heroku时我一直收到错误。我已经将Facebook dev / apps部分中的链接更改为实际域。

我在production.rb中有以下代码。对于" app_domain"部分,我试图提出所有类型的应用程序域变体(域名,domain.com,heroku应用程序名称等),但我不知道应该去哪里。

我是一名新编码员,所以非常感谢任何帮助!

# Email for omniauth facebook auth
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => config.app_domain }
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com', 
port: '587',
enable_starttls_auto: true,
user_name: 'someuser',
password: 'somepass',
authentication => :plain,
domain => 'somedomain.com'
}
  

NoMethodError:未定义的方法`app_domain'对

     

   /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/railtie/configuration.rb:95:in
     

method_missing' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/config/environments/production.rb:100:in 阻止&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/railtie.rb:210:in   instance_eval' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/railtie.rb:210:in 配置&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/config/environments/production.rb:1:in   <top (required)>' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in需要&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in block in require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in load_dependency&#39 ;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:594:in 块(2在&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:593:in   each' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:593:in 阻止&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in   instance_exec' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in 运行&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:55:in   block in run_initializers' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:44:in 各&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:44:in   tsort_each_child' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:54:in run_initializers&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:288:in   initialize!' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/config/environment.rb:5:in &#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in阻止在需要& #39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in load_dependency' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in要求&#39 ;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:264:in   run_tasks_blocks中的require_environment!' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:367:in 阻止&#39;          /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:55:in   `定义&#39;中的块(2级)          任务:TOP =&gt;环境          (通过使用--trace运行任务查看完整跟踪)! !预编译资产失败。

1 个答案:

答案 0 :(得分:1)

您的错误消息“未定义的方法`app_domain'”源自此行:

config.action_mailer.default_url_options = { :host => config.app_domain }

正如它所说,您尚未在app_domain选项上分配config属性。 Action Mailer是发送电子邮件的Rails的一部分,它使用此设置生成返回应用程序的链接。

您只需将config.app_domain = "myapp.herokuapp.com"添加到config/environments/production.rb文件的顶部即可。但这是硬编码的;另一种方法是使用环境变量。

Heroku uses their config command for this;在终端中运行heroku config:set APP_DOMAIN=myapp.herokuapp.com进行设置,然后在Ruby应用程序中使用ENV['APP_DOMAIN']来访问它。所以你的配置行看起来像这样:

config.action_mailer.default_url_options = { :host => ENV['APP_DOMAIN'] }

最后,您将domain设置作为底部smtp_settings块的一部分。您可能也希望使用新设置。