On Mar 3, 2012, at 3:41 PM, Fresh Mix wrote:

> 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

Anything you print all by itself inside an erb block gets an implicit 
conversion to string. But a comparison or concatenation isn't going to do the 
same for you. 'en' != :en, for example. You could try <%= I18n.locale == 'en' ? 
'true' : 'false' %> and compare what you get with <%= I18n.locale.to_s == 'en' 
? 'true' : 'false' %> to see if this is your issue.

Walter

> 
> -- 
> 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.
> 

-- 
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