I have in my project rails 3.2 two languages.
I18n.default_locale = :en
LANGUAGES = [
['English',
'en'],
["Español".html_safe, 'es']
]
The registered users can create new posts in these languages.
My question is:
In my post action index, if user in these moment the language is for example :en. How can I filter and show only posts that are in the English language or if user in these moment the language is for example :es. How can I filter and show only posts that are in the Spanish language?
Thank you very much!
I think the best way to achieve that is to add a “language” column in your Posts table and to set this attribute when the post is created by testing i18n.locale. Then you filter posts with a simple query like:
The best thing to do would be to let the user choose the language when creating a new post with a select field for instance, and setting the default according to the current locale.
Because, an English user should be able to write Spanish posts if he wants to, shouldn’t he?