But I ran into one issue when creating emails that contain links back to my server.
Because you are sending an email to a remote machine, you need to include absolute URLs in your links.
You can define that in a config file but the example given in the Railscast is now deprecated, plus when I first tried it, my app was not picking it up and all my links were still relative.
You two things for this to work:
1: In your application.rb or environments/development.rb add a line like this in the configuration block, replacing craic.com with your domain
config.action_mailer.default_url_options = { :host => "craic.com" }The application.rb file applies to all environments. Putting this in development.rb or production.rb lets you use different hosts for each environment.
2: There are several ways to specify a url to pass into a link_to call in Rails - but only one seems to work.
Specify the urls for your links using <your_model>_url(<your_object>) - not <your_model>_path(<your_object>) and not url_for(...). I tend to use mymodel_path in links in regular web pages so I can't just cut and paste code into a mailer view.
Here is an example that works:
<%= link_to object.name, mymodel_url(object) %>
...produces...
<a href="http://craic.com/mymodels/1">My Object</a>
No comments:
Post a Comment