Rails - 设计/Omniauth - 无方法错误配置
Posted
技术标签:
【中文标题】Rails - 设计/Omniauth - 无方法错误配置【英文标题】:Rails - Devise/Omniauth - No Method Error Configuration 【发布时间】:2014-09-12 18:29:13 【问题描述】:我正在尝试将 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
block in ' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/railtie.rb:210:ininstance_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
configure' /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
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:inblock 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' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inrequire' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:594:in
block(2级)在 ' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:593:ineach' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/engine.rb:593:in
block in ' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:ininstance_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
run' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:55:inblock 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
each' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/initializable.rb:44:intsort_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' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:288:ininitialize!' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/config/environment.rb:5:in
' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:inrequire' /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:inload_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
require' /tmp/build_9557c4b1-3f72-41e9-bc67-afe937d8b044/vendor/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/application.rb:264:inrequire_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
block 在 run_tasks_blocks' /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 `定义中的块(2级)' 任务:TOP => 环境 (通过使用 --trace 运行任务查看完整跟踪)! !预编译资产失败。
【问题讨论】:
【参考方案1】:您的错误消息“未定义的方法 `app_domain'”源于此行:
config.action_mailer.default_url_options = :host => config.app_domain
正如它所说,您尚未在 config
选项上分配 app_domain
属性。 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
块的一部分。您可能也希望使用您的新设置。
【讨论】:
谢谢亚历克斯!通过您的更改消除了这些错误,我在这个答案中发现了一些错误:***.com/questions/24272716/…以上是关于Rails - 设计/Omniauth - 无方法错误配置的主要内容,如果未能解决你的问题,请参考以下文章
在 Rails 3 中设置环境变量(设计 + Omniauth)
Ruby on rails omniauth-twitter 和设计
Rails Devise Omniauth new_user_registration_url