hi
I have a problem to store the current locale (language) used by a
user .
I have this model that represent the locale:
class LocaleModel < ActiveRecord::Base
@@global_locale = nil
def self.global
@@global_locale
end
def self.global=( locale )
if locale.is_a? Locale
@@global_locale = locale
elsif locale.is_a? String
locale = LocaleModel.find(:first, :conditions => [''short = ?
'',
locale])
return false if (! locale)
@@global_locale = locale
else
# empty
@@global_locale = nil
end
end
def master?
self.master == true
end
end
In my application controller I do :
LocaleModel.global = ''fr'' if LocaleModel.global == nil
And in some other controller I have an action that is used to change
the locale:
def change_locale
LocaleModel.global = params[:lang]
end
The problem is that when I change the view or reload the page, the
locale always resets. How come ?
Thank You
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
hi
I have a problem to store the current locale (language) used by a user .
I have this model that represent the locale:
class LocaleModel < ActiveRecord::Base
@@global_locale = nil
def self.global
@@global_locale
end
def self.global=( locale )
if locale.is_a? Locale
@@global_locale = locale
elsif locale.is_a? String
locale = LocaleModel.find(:first, :conditions => [''short = ?
'',
locale])
return false if (! locale)
@@global_locale = locale
else
# empty
@@global_locale = nil
end
end
def master?
self.master == true
end
end
In my application controller I do :
LocaleModel.global = ''fr'' if LocaleModel.global == nil
And in some other controller I have an action that is used to change the
locale:
def change_locale
LocaleModel.global = params[:lang]
end
The problem is that when I change the view or reload the page, the
locale always resets. How come ?
Thank You
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Sep-12 14:13 UTC
Re: Locale model to store language value not working
I think you misunderstand what''s a global variable in Ruby/Rails It''s not storing data between sessions. Whenever a user requests a page, it''s reset. You must use the session object to store data between requests --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-12 14:15 UTC
Re: Locale model to store language value not working
On 12 Sep 2008, at> > def change_locale > LocaleModel.global = params[:lang] > end > > The problem is that when I change the view or reload the page, the > locale always resets. How come ?Because classes are reloaded between requests in development mode. Fred --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---