Walter Davis wrote in post #1049976:
> On Mar 3, 2012, at 3:17 PM, Fresh Mix wrote:
>
>>>
>> <a href="/welcome/index?locale=en">in english</a>
>>
>> Why? If I18n.locale == 'en'  there should not be link.
>>
>> So why "if (I18n.locale != 'en')" is true ?
>
> Have you followed these steps:

I made it like this:

class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :set_locale

  def set_locale
    locale = params[:locale] || session[:locale] || 
extract_locale_from_accept_language_header
    if(locale.match /^(ru|en)$/)
      I18n.locale = locale
      session[:locale] = locale
    end
  end

  private

  def extract_locale_from_accept_language_header
      request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
  end

end


----

And if <%= I18n.locale %> prints on page "en" so I18n.locale is set

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to