I have been googling for about 90 minutes now and still don\'t have an answer to this. Where do I set default_url_options
? I\'ve already set it for conf
You can set default url options in the Application Controller:
class ApplicationController < ActionController::Base
def default_url_options
{:locale => I18n.locale}
end
end
http://guides.rubyonrails.org/action_controller_overview.html#default_url_options
go to config/environments/test.rb
Rails.application.routes.default_url_options[:host] = 'localhost:3000'
You need to add the following line at every environment:
config.action_mailer.default_url_options = { :host => "yourhost" }
That way, it can work in all environments and could be different from environment to environment. For example:
development.rb
config.action_mailer.default_url_options = { :host => "dev.yourhost.com" }
test.rb
config.action_mailer.default_url_options = { :host => "test.yourhost.com" }
production.rb
config.action_mailer.default_url_options = { :host => "www.yourhost.com" }
I solved the issue by configuring environment.rb as
YourApp::Application.default_url_options = YourApp::Application.config.action_mailer.default_url_options
You need to set default_url_options for action mailer against each environment like development, testing, staging and production etc.
Reference: Missing host to link to! Please provide :host parameter or set default_url_options[:host]
Funny thing, that setting config.action_mailer.default_url_options
does not help for me. Also, messing around with environment-independent settings in places I felt like it does not belong was not satisfying for me. Additionally, I wanted a solution that worked when generating urls in sidekiq/resque workers.
My approach so far, which goes into config/environments/{development, production}.rb
:
MyApp::Application.configure do
# Stuff omitted...
config.action_mailer.default_url_options = {
# Set things here as usual
}
end
MyApp::Application.default_url_options = MyApp::Application.config.action_mailer.default_url_options
This works for me in rails >= 3.2.x.
Your::Application.routes.draw do
default_url_options :host => "example.com"
# ... snip ...
end
Somewhere in routes.rb
:)