Heroku/devise - 缺少要链接的主机!请提供 :host 参数或设置 default_url_options[:host] [英] Heroku/devise - Missing host to link to! Please provide :host parameter or set default_url_options[:host]

查看:32
本文介绍了Heroku/devise - 缺少要链接的主机!请提供 :host 参数或设置 default_url_options[:host]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用推送到 heroku.我还在开发中.我使用带有可确认模块的设计.

I am trying to push my app on heroku. I am still in dev. I use devise with the confirmable module.

当我尝试使用 heroku 控制台添加用户时,出现此错误:

When I try to add a user with the heroku console I got this error:

Missing host to link to! Please provide :host parameter or set default_url_options[:host]

在测试和开发环境中,我有以下几行:

in test and dev environment i have the following line:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

我没有在生产环境中设置一些东西.

I don't have set up something in the production environment.

我试过推

config.action_mailer.default_url_options = { :host => 'mywebsitename.com' }
config.action_mailer.default_url_options = { :host => 'heroku.mywebsitename.com' }

但它也不起作用..

我在网上看到它可能与 ActionMailer 有关,但我不知道我必须配置什么.非常感谢您的想法!

I see on the web that it could be related to ActionMailer but I don't know what I have to configure. Many thanks for your idea!

为了不让我的应用程序在我推送 heroku 时崩溃,我把它放在我的 env/test.rb 和我的 env/dev.rb 中(不是在 env.rb 我认为这是因为它是一个 rails 3 应用程序)

In order to not make my app crashes when I push on heroku I put this in my env/test.rb and my env/dev.rb (not in env.rb I think it is because it's a rails 3 app)

config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }

但是当我尝试在 heroku 控制台中创建用户时:

But when I tried to create a user in the heroku console:

User.create(:username => "test", :email => "test@test.com", :password => "test1234", :password_confirmation => "test1234", :confirmed_at => "2010-11-03 14:11:15.520128")

这是我得到的错误:

ActionView::Template::Error: Missing host to link to! Please provide :host parameter or set default_url_options[:host]
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:473:in `url_for'
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_dispatch/routing/url_for.rb:132:in `url_for'
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_view/helpers/url_helper.rb:99:in `url_for'
/home/slugs/.../mnt/.bundle/gems/ruby/1.8/gems/actionpack-3.0.0/lib/action_dispatch/routing/route_set.rb:195:in `user_confirmation_url'

已编辑 (2)

当我在控制台输入 heroku 日志时,我得到了这个 ==>production.log <== 所以我认为当在 heroku 上部署时,它已经在生产中了.

EDITED (2)

When I type heroku logs on console I got this ==> production.log <== So I think when one deploys on heroku it's already in production.

我这样配置 env/prod.rb:

I configure the env/prod.rb like this:

config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }

现在当我尝试创建用户时出现此错误:

and now I have this as error when I try to create a User:

Errno::EAFNOSUPPORT: Address family not supported by protocol - socket(2)
/usr/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:551:in `initialize'
/usr/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:551:in `open'
/usr/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:551:in `do_start'
/usr/ruby1.8.7/lib/ruby/1.8/timeout.rb:62:in `timeout'

推荐答案

您需要将此添加到您的 environment.rb

You need to add this to your environment.rb

  config.action_mailer.default_url_options = { :host => 'localhost' }

确保将 host 更改为您的生产 url,并将其保留为 localhost 以进行开发.这是给邮寄者的,它需要一个默认的电子邮件来发送确认等通知......

Make sure you change host to your production url and keep it localhost for development. This is for the mailer, it needs a default email to send out notices such as confirmations etc...

您应该检查 heroku 服务器上的日志 heroku logs 从控制台运行它,它会告诉您确切的错误.

You should check the logs on the heroku server heroku logs run that from the console and it will tell you the exact error.

推送到 heroku 时,您需要使用 heroku 子域配置 environment.rb 文件:

When you push to heroku you need to configure the environment.rb file with the heroku subdomain:

config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }

<小时>

根据版本,这应该放在 production.rb 中,而不是 environment.rb.

这篇关于Heroku/devise - 缺少要链接的主机!请提供 :host 参数或设置 default_url_options[:host]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆