ben*_*itr 176 ruby-on-rails actionmailer heroku devise
我想在heroku上推送我的应用程序.我还在开发中.我使用了可确认模块的设计.
当我尝试使用heroku控制台添加用户时出现此错误:
Missing host to link to! Please provide :host parameter or set default_url_options[:host]
Run Code Online (Sandbox Code Playgroud)
在测试和开发环境中,我有以下行:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
Run Code Online (Sandbox Code Playgroud)
我没有在生产环境中设置一些东西.
我试过推
config.action_mailer.default_url_options = { :host => 'mywebsitename.com' }
config.action_mailer.default_url_options = { :host => 'heroku.mywebsitename.com' }
Run Code Online (Sandbox Code Playgroud)
但它也不起作用..
我在网上看到它可能与ActionMailer有关,但我不知道我要配置什么.非常感谢你的想法!
嗨,
为了在我推动heroku时不让我的应用程序崩溃,我把它放在我的env/test.rb和我的env/dev.rb(不在env.rb中,我认为这是因为它是rails 3应用程序)
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在heroku控制台中创建用户时:
User.create(:username => "test", :email => "test@test.com", :password => "test1234", :password_confirmation => "test1234", :confirmed_at => "2010-11-03 14:11:15.520128")
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
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'
Run Code Online (Sandbox Code Playgroud)
当我在控制台上键入heroku日志时,我得到了这个==> production.log <==所以我认为当一个人在heroku上部署它已经在生产中了.
我像这样配置env/prod.rb:
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试创建用户时,我将此作为错误:
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'
Run Code Online (Sandbox Code Playgroud)
the*_*gah 239
您需要将此添加到您的 environment.rb
config.action_mailer.default_url_options = { :host => 'localhost' }
Run Code Online (Sandbox Code Playgroud)
确保更改host为生产URL并将其保留为localhost以进行开发.这是邮件,它需要一个默认的电子邮件发送通知,如确认等...
你应该检查heroku logs从控制台运行的heroku服务器上的日志,它会告诉你确切的错误.
当您推送到heroku时,您需要environment.rb使用heroku子域配置该文件:
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
Run Code Online (Sandbox Code Playgroud)
根据版本,这应该进入production.rb,而不是environment.rb.
ben*_*itr 37
好,
首先,您必须使用此命令行安装sendgrid gem:
heroku addons:add sendgrid:free
Run Code Online (Sandbox Code Playgroud)
然后你只需要像这样配置你的env/dev.rb和env/prod.rb:
ENV/dev.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
Run Code Online (Sandbox Code Playgroud)
ENV/prod.rb
config.action_mailer.default_url_options = { :host => 'yourapp.heroku.com' }
Run Code Online (Sandbox Code Playgroud)
推上git和heroku.它应该工作..
Ros*_*oss 22
Codeglot上面的anwser完成了这项工作,但我们想要更灵活的东西,所以我们这样做了:
在Heroku上,我们运行多个生产环境进行分段和测试,因此我们需要一个灵活的production.rb环境文件解决方案.
在production.rb
config.action_mailer.default_url_options = { :host => ENV['MAILER_URL'] }
Run Code Online (Sandbox Code Playgroud)
然后像这样为您的应用程序设置MAILER_URL环境变量
heroku config:set MAILER_URL=my-awesome-app.herokuapp.com --app my-awesome-app
Run Code Online (Sandbox Code Playgroud)
Mik*_*ike 18
如果你在Cedar上运行:
heroku addons:add sendgrid:free从你的控制台运行.
config/environments/production.rb在您的应用中添加以下行.
.
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com'
}
ActionMailer::Base.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'YOUR-DOMAIN-HERE.COM' }
Run Code Online (Sandbox Code Playgroud)
mau*_*lus 13
我必须做很多事情才能让它在生产环境中工作:在我的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"
Run Code Online (Sandbox Code Playgroud)
这与Rails 4和Devise 3有关
这是一个需要考虑的技巧.它将更容易切换服务器和环境,并在heroku的自定义域中更改域.
而不是硬编码主机名,而是从请求中读取它.这是我的一个简单应用程序的示例.
class MyMailController < ApplicationController
before_filter :set_host_from_request, only: [:create]
....
private
def set_host_from_request
ActionMailer::Base.default_url_options = { host: request.host_with_port }
end
end
Run Code Online (Sandbox Code Playgroud)
在简单示例中,我只有一个动作,即创建,导致发送电子邮件.您可以在application_controller.rb中添加before_filter而不使用排除项,以使其始终存储主机名.
PRO:
CON:
如果没有default_url_options,则无法在控制台中手动发送
#config.action_mailer.default_url_options = { :host => 'mydomain.com' }
$rails console
User.invite!(email: "ceo@example.com")
ActionView::Template::Error: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
...stacktrace
Run Code Online (Sandbox Code Playgroud)
如果您能看到我无法解决的弊端,请分享!谢谢
| 归档时间: |
|
| 查看次数: |
86980 次 |
| 最近记录: |