Skip to content

Instantly share code, notes, and snippets.

@ywatai
Created October 12, 2011 00:32
Show Gist options
  • Select an option

  • Save ywatai/1279885 to your computer and use it in GitHub Desktop.

Select an option

Save ywatai/1279885 to your computer and use it in GitHub Desktop.
i18n filter for rails 3.0.x (from tutorial)
class ApplicationController < ActionController::Base
protect_from_forgery
# l19n by url parameter
before_filter :set_locale
private
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
def default_url_options(options={})
logger.debug "default_url_options is passed options: #{options.inspect}\n"
{ :locale => I18n.locale }
end
end
AppName::Application.routes.draw do
# switch locale with parameter
scope "/(:locale)", :locale => /en|ja/ do
# your application routes
# resources :posts
end
# default locale
# resources :posts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment