Hi Nicolay,
It''s not a good idea to access the session (the session is in the
controller) from the model.
For localization of rails apps have a look at these pages in the wiki:
http://wiki.rubyonrails.com/rails/search/?query=localization
The Salted Hash Login Generator also includes a library for dealing with
localization.
If your mody really needs to know which locale it should be working in
it''s probably a better idea to store the locale ("lang") in
the session and pass the value to the model:
def title (locale)
locale = ''en'' if locale.nil?
self.send((locale + ''_title'').to_sym)
end
This title function accepts the locale as an argument. Just in case the locale
is nil the locale is set to engrish. The rest of the table name is added to the
locale and converted to a symbol, wich is fed to the send method.
Mind you, I''m just starting out with Ruby, so there''s probably
a nicer way to do this. ;)
Ruairi
----- Original Message -----
From: Nickolay Kolev
Sent: 5/31/2005 6:43:23 AM
To: rails@lists.rubyonrails.org
Subject: [Rails] Access session in the model
Hi all,
I am making a dual language interface for ana online
catalog. I am thinking about making it the following way:
in the model:
def title
if @session[''lang''] == ''en''
return self.en_title
else
return self.de_title
end
end
So when I call catalog_entry.title it would check which
language is in the session and give me the correct title.
Before starting coding it I would like to get some
opinions if this would be a good solution? Any
suggestions?
Many thanks in advance,
Nicky
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails