0

I'm finishing the different localizations of my site and i got a little issue in Devise email templates.

In confirmation email for instance, i have translated it all, but the link to confirm the account is auto generated using this snippet:

<%= link_to t('devise.mailer.confirmation_instructions.confirm_link'), confirmation_url(@resource, :confirmation_token => @token) %>

This auto generated link points always to my .com web version and i want it to be conditional depending on the domain (.com/.es). When the link is not auto generated i can accomplish that using:

if request.host.split('.').last == "com"

or

if request.host.split('.').last == "es"

But in this case, i don't know how i can do it.

Any suggestion?

Thanks.

Rubén Jiménez
  • 1,835
  • 5
  • 21
  • 29
  • do you store current language setting somehow for the user? – Bart Jan 12 '14 at 06:20
  • You can pass the `:host` param to `url` helper. – Bart Jan 12 '14 at 06:23
  • I have a column in user's table in which i store the browser's language from the user. How could i pass the :host param? <%= link_to t('devise.mailer.confirmation_instructions.confirm_link'), confirmation_url(@resource, :confirmation_token => @token, :host => 'www.example.com') %> this way? – Rubén Jiménez Jan 12 '14 at 06:28

1 Answers1

1

You could add the :host param to your confirmation_url(@resource, :confirmation_token => @token), and look up the correct host in your translation table:

confirmation_url(@resource, :confirmation_token => @token, host: t('host'))

In your yaml file, you 'translate' the correct host for the user's language, like

en:
  host: 'www.example.com'
Danny
  • 5,945
  • 4
  • 32
  • 52