# Locale model to store language value not working

**URL:** <https://www.ruby-forum.com/t/locale-model-to-store-language-value-not-working/148411>\
**Category:** Rails\
**Created:** [September 12, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/locale-model-to-store-language-value-not-working/148411 "2008-09-12T16:15:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jalb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f17d59/32.png) [@jalb](https://www.ruby-forum.com/u/jalb)\
**Post date:** [September 12, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/locale-model-to-store-language-value-not-working/148411/1 "2008-09-12T16:15:37Z")

</div>

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
