Posted By

harrikauhanen on 07/06/10


Tagged

locale routing


Versions (?)

Set locale with prefix in URL e.g. http://mysite.com/fi/items


 / Published in: Rails
 

  1. # config/routes.rb:
  2.  
  3. scope "(/:locale)" do
  4. resources :items
  5. end
  6.  
  7.  
  8. # app/application_controller.rb
  9.  
  10. class ApplicationController < ActionController::Base
  11. protect_from_forgery
  12.  
  13. before_filter :set_locale
  14. def set_locale
  15. I18n.locale = params[:locale]
  16. end
  17.  
  18. def default_url_options(options={})
  19. {:locale => I18n.locale}
  20. end
  21. end
  22.  
  23.  
  24. # config/application.rb or config/environments/production.rb:
  25.  
  26. Tassuttelijat::Application.configure do
  27. config.i18n.default_locale = :fi
  28. end
  29.  
  30. # Make sure the previous lines are before this one:
  31. Tassuttelijat::Application.initialize!

Report this snippet  

You need to login to post a comment.