Posted 7 months ago. Visible to the public.

Rails: How to provide a public link in a mail

Lets say we have a user with a contract whereas contract is a mounted carrierwave file.

Now we want to send the link to the contract in a mail. For this use case join the root_url with the public contract path in the mailer view:

Plain text email

Copy
URI.join(root_url, @user.contract.url)

HTML email

Copy
link_to('Show contract', URI.join(root_url, @user.contract.url).to_s)

Note: You need to follow http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views or Make ActionMailer use the current request host and protocol for URL generation to have the correct path and port. If you don't store the files local but remote (e.g. S3) the url will already include the full url.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Emanuel De
Last edit:
6 months ago
by Tobias Kraze
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more