Rails 3 localized routes and show resources

I am rewriting routes on a Rails 3.2 server, so this language is part of the URL. My route.rb file looks like this:

scope ":lang", :lang => /es|fr|it|pt|en|de/ do
    resources :users
end

Almost all URLs work fine by adding language strings, i.e.

http://mydomain/es/somecontroller/someaction

The problem is with show actions, links do not work. This line:

<%= link_to "Show", @my_user %>

Causes a "Routing Error" as follows:

No route matches {:action=>"show", :controller=>"users", :lang=>##User serialization##}

What am I doing wrong?

EDIT . Ok, solution found . Thanks to Cage and a little research, there is a solution.

You only need the ApplicationController method:

def self.default_url_options
  { :lang => FastGettext.locale }
end

And everything works flawlessly !! No need to rewrite links at all.

+3
source share
1 answer

, , , : id . ,

 <%= link_to "Show", user_path(@my_user.id) %>

, http://guides.rubyonrails.org/routing.html

+1

All Articles