Locale model to store language value not working

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

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

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