rubyruby-on-rails-5cloud9-idecloud9aws-cloud9

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


Trying to preview my mailer in development, but I'm getting the above error. (Using Michael Hartl Tutorial).

I believe it's not working because of my host. However, using cloud 9 I'm struggling to find what my host is. In the book it's defined as host ='rails-tutorial-mhartl.c9users.io' for the Cloud IDE, but this is unique to the book writer.

I tried using localhost, which hasn't worked and my dev url is different to whats in the book if this relates: "..0.vfs.cloud9.us-east-2.amazonaws.com/"

Essentially if I can find out my unique Cloud IDE host the problem should get fixed, but I don't know where to locate this

development.rb

config.action_mailer.raise_delivery_errors = true  
config.action_mailer.delivery_method = :test  
host = 'localhost:8080' 
config.action_mailer.default_url_options = { host: host, protocol: 'http' }

account_activation.html.erb

<h1>Sample App</h1>
<p>Hi <%= @user.name %>,</p>

<p>
  Welcome to the Sample App! Click on the link below to activate your account:
</p>

<%= link_to "Activate", edit_account_activation_url(@user.activation_token,
                                                email: @user.email) %>

The page should load with the email preview, but full error message is:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true


Solution

  • If you are using Rails 5, try this:

    Rails.application.routes.default_url_options[:host] = "XXX"

    Found this post about Rails 4 and there was a similar discussion in the Rails repository on Github