I am new to rails (using 3.2.1) and I have been following the i18n-guide in guide rails .
I am having problems with this section:
The URLs are likely to look like this: www.example.com/en/books (which downloads English) and www.example.com/nl/books (which downloads the locale of the Netherlands). This is achieved using the "over-riding default_url_options" strategy above: you just have to configure routes using the path_prefix option this way
But when I use <% = products_path%> in my views, it returns: / products? locale = en
and I want it to return / nl / products
When I enter the URL in the browser (e.g. localhost: 3000 / nl / products), the page displays the correct locale.
What am I missing?
Application controller:
class ApplicationController < ActionController::Base
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
def default_url_options(options = {})
{ :locale => I18n.locale }
end
end
routes:
scope "/:locale" do
resources :products
end
match '/:locale' => 'products#index'
rake routes:
products GET /products(.:format) products
POST /products(.:format) products
new_product GET /products/new(.:format) products
edit_product GET /products/:id/edit(.:format) products
product GET /products/:id(.:format) products
PUT /products/:id(.:format) products
DELETE /products/:id(.:format) products
GET /:locale/products(.:format) products
POST /:locale/products(.:format) products
GET /:locale/products/new(.:format) products
GET /:locale/products/:id/edit(.:format) products
GET /:locale/products/:id(.:format) products
PUT /:locale/products/:id(.:format) products
DELETE /:locale/products/:id(.:format) products
/:locale(.:format) products
root / products
source
share