3

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

Christian
  • 4,902
  • 4
  • 24
  • 42
marca
  • 45
  • 2
  • 7

1 Answers1

3

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

Christian
  • 4,902
  • 4
  • 24
  • 42
  • Wow, great! Not sure how that worked, but it did - thank you – marca Aug 03 '19 at 20:46
  • 1
    No worries. Did as you said, the above worked using the "XXX", but I've now updated the :host to match the root URL - thanks will also look into the links in future to get more of an understanding – marca Aug 04 '19 at 17:46
  • 1
    just change "XXX" to your root URL and it works. thanks – Fazal Karim Aug 31 '22 at 20:11