Posted about 4 years 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 Archive 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 Archive 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.

Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Avatar
Emanuel De
Last edit:
about 4 years 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 short-lived cookies to improve usability.
Accept or learn more