Problem:
Missing host to link to! Please provide :host parameter or set default_url_options[:host] when sending emails.
Solution:
You can pass host parameter to url functions, but it’s cleaner to configure it with a before_filter globally in your application_controller.rb:
# application_controller.rb before_filter :mailer_set_url_options ... def mailer_set_url_options ActionMailer::Base.default_url_options[:host] = request.host_with_port end
5 comments ↓
Thanks !!
solved my problem.
Or put it in environment.rb
config.action_mailer.default_url_options = { :host => “example.com” }
@Sandy,
While that would work, the before_filter approach has the added benefit of being dynamic to the environment Rails is currently running in. This gives you the flexibility to have links in development point to development, not production.
Hello,
thanks for the infos, you solved my issue, now I’m using this in my application.rb and it works well for my needs.
config.action_mailer.default_url_options = { :host => Rails.env == “production” ? ‘domain.com’ : ‘localhost:3000′ }
Francesco, it’s cleaner if you just let the environtment configs handle the default_url_options
Leave a Comment