Ruby on rails Heroku/Desive-缺少链接到的主机!请提供:主机参数或设置默认\u url\u选项[:主机]
我正在尝试在heroku上推送我的应用程序。我还在德夫。 我用可确认模块设计 当我尝试使用heroku控制台添加用户时,出现以下错误:Ruby on rails Heroku/Desive-缺少链接到的主机!请提供:主机参数或设置默认\u url\u选项[:主机],ruby-on-rails,heroku,devise,actionmailer,Ruby On Rails,Heroku,Devise,Actionmailer,我正在尝试在heroku上推送我的应用程序。我还在德夫。 我用可确认模块设计 当我尝试使用heroku控制台添加用户时,出现以下错误: Missing host to link to! Please provide :host parameter or set default_url_options[:host] 在测试和开发环境中,我有以下几行代码: environments/development.rb和environments/test.rb 我没有在生产环境中设置任何东西 我试着用它来
Missing host to link to! Please provide :host parameter or set default_url_options[:host]
在测试和开发环境中,我有以下几行代码:
environments/development.rb和environments/test.rb
我没有在生产环境中设置任何东西
我试着用它来推动
config.action_mailer.default_url_options = { :host => 'mywebsitename.com' }
config.action_mailer.default_url_options = { :host => 'heroku.mywebsitename.com' }
但是它也不起作用
我在网上看到它可能与ActionMailer有关,但我不知道我必须配置什么。
非常感谢你的想法
编辑:
嗨
为了不让我的应用程序在我推heroku时崩溃,我把它放在我的env/test.rb和env/dev.rb中(我想不是在env.rb中,因为它是rails 3应用程序)
但当我试图在heroku控制台中创建用户时:
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 logs时,我得到了这个==>production.log您需要将它添加到您的
环境中。rb
config.action_mailer.default_url_options = { :host => 'localhost' }
确保将host
更改为您的生产url,并将其保留为本地主机以供开发。这是给邮寄者的,它需要一封默认的电子邮件来发送确认等通知
您应该检查heroku服务器上的日志,从控制台运行heroku日志,它会告诉您确切的错误 推送到heroku时,需要配置带有heroku子域的
environment.rb
文件:
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
根据版本的不同,这应该进入
production.rb
,而不是environment.rb
Ok
首先,您必须使用以下命令行安装sendgrid gem:
heroku addons:add sendgrid:free
然后您只需如下配置env/dev.rb和env/prod.rb:
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
环境/发展资源中心
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
环境/产品数据库
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
推git和heroku。如果您在Cedar上跑步,它应该会工作。:
config/environments/production.rb
中添加以下行Codeglot的anwser在上面做了这项工作,但我们想要更灵活一点的东西,所以我们这样做了: 在Heroku上,我们运行多个生产环境进行登台和测试,因此我们需要一个灵活的Production.rb环境文件解决方案 在生产中.rb
config.action_mailer.default_url_options = { :host => ENV['MAILER_URL'] }
然后为应用程序设置MAILER_URL环境变量,如下所示
heroku config:set MAILER_URL=my-awesome-app.herokuapp.com --app my-awesome-app
我必须做很多事情才能让它在生产环境中工作: 在我的
production.rb
文件(/config/environments/production.rb)中,我添加了以下内容:
Rails.application.routes.default_url_options[:host] = 'myappsname.herokuapp.com'
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
这是经过大量研究后,与Rails 4和Desive 3的合作
class ApplicationMailer < ActionMailer::Base
default from: 'yourmail@gmail.com'
layout 'mailer'
end
你现在可以走了。:) 嗨,山姆!对不起,我没弄明白。我只是在我的env.rb中添加了config.action\u mailer.default\u url\u options={:host=>'localhost'}行,但是我的rails 3应用程序在heroku上崩溃了。我是否也必须在env/prod.rb上添加一些内容?(对不起,我的英语很差。)另外,我是否必须将rails应用程序置于生产模式?谢谢
:host=>“yourapp.heroku.com”
这应该是您的域。例如,如果你的域名是yahoo.com,那么它应该是yahoo.heroku.com
,或者如果你已经设置了自定义域名,那么它将只是你的urlyahoo.com
谢谢Sam,我找到了解决方案。事实上,我没有sendgrid插件,我的smtp也没有配置。非常感谢您的支持!它不是将是config.action\u mailer.default\u url\u options={:host=>'yourapp.herokuapp.com'
,而不仅仅是config.action\u mailer.default\u url\u options={:host=>'yourapp.heroku.com'
?我在production.rb:/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.7/lib/rails/railtie/configuration中引用config.action\u mailer时遇到了这个错误。rb:77:inmethod\u missing':未定义的方法我不确定我能在这里提供帮助…您是否在块中引用了它?(Website::Application.configure do…config.action\u mailer.default\u url\u options={:host=>'yourapp.heroku.com'}…end)现在sendgrid命令是heroku addons:add sendgrid:starter(在上查看使用详细信息)default\u url\u options
的这种结构导致了一个错误,使我的预编译资产失败,仅供参考。当我将其改回`={host:'myappsname.herokuapp.com``时,它起了作用。
config.action_mailer.default_url_options = { :host => ENV['MAILER_URL'] }
heroku config:set MAILER_URL=my-awesome-app.herokuapp.com --app my-awesome-app
Rails.application.routes.default_url_options[:host] = 'myappsname.herokuapp.com'
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
class ApplicationMailer < ActionMailer::Base
default from: 'yourmail@gmail.com'
layout 'mailer'
end
config.action_mailer.default_url_options =
{ :host => 'yourapp.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'heroku.com',
user_name: 'yourmail@gmail.com',
password: 'yourgmailpassword',
authentication: 'login',
enable_starttls_auto: true
}