Hi,
I’m creating a simple Ruby on Rails based CMS. It will support multiple
languages. Therefore I’ve a table ‘pages’ and a table
‘page_translations’. The table ‘page’ contains a title and body in the
default language, the table ‘page_translations’ contain a title and body
for an other language.
Now I would like to have an easy way to retrieve the title and body of a
page given the current language (stored in the session). I would like to
put this logic in a model (the Page model, or maybe a new model like
‘TranslatedPage’). This way I don’t have to put ugly code in my
controllers and views everytime to fetch the page for the current
language.
However, it seems I can’t access @session from the model. Does anybody
have a good idea on how to implement this?
Thanks in advance!
Greetings,
On 24 Dec 2005, at 18:47, Matthias Pronk wrote:
However, it seems I can’t access @session from the model. Does anybody
have a good idea on how to implement this?
Try dropping the @ – use session instead of @session. Any good?
Yours,
Craig
Craig W. | t: +44 (0)131 516 8595 | e: [email protected]
Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.net
Matthias Pronk a écrit :
controllers and views everytime to fetch the page for the current
language.
However, it seems I can’t access @session from the model. Does anybody
have a good idea on how to implement this?
My 0.02$: I think you should normalize your tables, and have
DEFAULT_LANG= ‘en’
page_translations
id
lang CHAR(2) DEFAULT en
mycontent TEXT
then in your controller you simply do
MyController.show
@my_model = MyModel.find(12, :include => :page_translations,
:conditions => [‘lang = ?’, session[:lang]])
end
Why is this ugly ?