Search code examples
ruby-on-railsruby-on-rails-3localehostlink-to

Need To Add Locale To link_to Statement in a Mailer View


I have removed gem routing-filter from my Rails 3.2.13 application in preparation to upgrade it to Rails 4. The author(s) have a beta version for Rails 4 but I could never get it to work. I have implemented the normal Rails process for localization/internationalization. The last issue I need to resolve is a link_to statement that displays a thread in a mailer view.

When I was using routing-filter I had the link_to statement as below where I set @host in my mailer depending on the environment.

<%= link_to "#{t :view_thread}", micropost_url(@item), host: "#{@host}" %>

When I uninstalled routing-filter I started getting errors because of a missing locale when the attempt is made to send the email. It crashes and sends the application back to the landing page. The gem took care of this.

I have been searching for about an hour trying to find the correct syntax for this but I'm not finding any examples that include both the host and locale parameters. I have tried several guesses but I get syntax errors.

Any help would be appreciated. I will keep searching and trying.


Solution

  • Here is the solution I came up with. I was not sure where the locale clause should go related to the host clause. I decided to try the statement below and it worked.

    <%= link_to "#{t :view_thread}", micropost_url(@item, locale: I18n.locale.to_s), host: "#{@host}" %>