Ahh, yeah, that's tricky. I think the problem is that you *should* be passing that locale to the find method in the controller, not the model, since the model isn't *supposed* to know about the session's info. In your case, you may have to break the rules a little bit and access session info in the model<http://www.google.com/search?q=rails+access+session+from+model&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a>, even though it's wrong (unless someone has a better way).
On Thu, Feb 12, 2009 at 8:53 AM, Alejandro <[email protected]> wrote: > > But I need the locale in the model, and as far as I know, it can't be > accessed from the model (and it shouldn't be because it would break > the MVC principles). > > On Feb 11, 6:43 pm, Bruno Bornsztein <[email protected]> > wrote: > > Couldn't you store that information in the session or cookie instead of > the > > Thread?http://apidock.com/rails/CGI/Session/CookieStore > > > > On Sat, Feb 7, 2009 at 8:49 AM, Alejandro <[email protected]> wrote: > > > > > @jak4 - If a user wants to see content in other language than the > > > actual, he must just choose the desired language from the language bar > > > (in the header in my case). Tagging could be an option, but I preffer > > > doing it like this. > > > > > @bruno - Right now I don't know how to put this on a plugin, I'll > > > check that out. > > > Do you know any alternative to the thread thing? > > > > > P.D.: Congrats for your child :) > > > > > On Feb 6, 8:34 pm, jak4 <[email protected]> wrote: > > > > I see. But what if a spanish user wants to see english content? If > > > > each piece of content is assigned a language why not just tag it > > > > accordingly? > > > > Tagging wouldn't need updating the models, filtering/showing language > > > > specific content is still possible and it's actually DRY. > > > > > > On Feb 6, 11:28 pm, Bruno Bornsztein <[email protected]> > > > > wrote: > > > > > > > @Alejandro, > > > > > Sounds like a very clever solution ... I think it'd be cool to wrap > > > this up > > > > > into a plugin (with its own migrations to add the needed colums) so > > > others > > > > > could use it. > > > > > > > @jak4 - he's adding the columns so he can record which locale each > > > piece of > > > > > content was created in. In theory, it might be enough to just check > the > > > > > locale of the user who created it, but this might not always be the > > > same (an > > > > > 'en' user might have created a blog post in 'es'). > > > > > > > Then, he can just show spanish content to spanish users, english to > > > english > > > > > users, etc. > > > > > > > Nice work! > > > > > bruno > > > > > > > On Fri, Feb 6, 2009 at 3:19 PM, jak4 <[email protected]> > > > wrote: > > > > > > > > I don't see your point. > > > > > > > > Why add it to so many models. What will this accomplish excactly? > An > > > > > > example would be helpful. > > > > > > > > This is what I don't get > > > > > > > > > My idea is that a user should see every piece of content in the > > > > > > > language he has chosen. > > > > > > > > regards > > > > > > jak4 > > > > > > > > On Feb 5, 5:19 pm, Alejandro <[email protected]> wrote: > > > > > > > I'm just doing this. I added the localte to the models > > > > > > > user,post,forum,activity and clipping. I also added the locale > to > > > the > > > > > > > session. > > > > > > > My idea is that a user should see every piece of content in the > > > > > > > language he has chosen. > > > > > > > The problem is getting the locale that lives in the session > from > > > the > > > > > > > models when creating them. Also when finding them, because I > wanted > > > to > > > > > > > override the find method of those entities to include the > locale in > > > > > > > every find invocation, to do that I used this: > > > > > > > > > def self.find(*args) > > > > > > > with_scope(:find=>{ :conditions=>"posts.language='# > > > > > > > {UserInfo.current_locale}'" }) do > > > > > > > super(*args) > > > > > > > end > > > > > > > end > > > > > > > > > I know I could just use the controllers to pass the locale, but > I > > > > > > > would have to look for every invocation to find, create and > others > > > and > > > > > > > pass the locale. I prefer doing this in a more generic way. > > > > > > > > > The workaround I found is creating a module (UserInfo) that > stores > > > the > > > > > > > locale in the current thread: > > > > > > > > > module UserInfo > > > > > > > def self.current_locale > > > > > > > Thread.current[:locale] > > > > > > > end > > > > > > > > > def self.current_locale=(locale) > > > > > > > Thread.current[:locale] = locale > > > > > > > end > > > > > > > end > > > > > > > > > the thing with this is that I need a web server that uses the > same > > > > > > > thread to handle all invocations of a user during his session. > > > > > > > I've tried this solution with WEBrick and it works, but in > > > production > > > > > > > I use FASTCGI and I couldn't find any information of how it > handles > > > > > > > the session. > > > > > > > > > Any help will be appreciated. > > > > > > > > > On Jan 21, 3:16 pm, Bruno Bornsztein < > [email protected]> > > > > > > > wrote: > > > > > > > > > > No, there isn't. You'd have to add it yourself, either by > adding > > > a > > > > > > locale > > > > > > > > column to user, or storing the users locale in the session. > > > > > > > > > > On Wed, Jan 21, 2009 at 9:37 AM, jak4 < > [email protected] > > > > > > > > wrote: > > > > > > > > > > > Hi, > > > > > > > > > > > is there already an mechanism to switch the language > > > on-the-fly? Such > > > > > > > > > as that the user can change his prefered language and > doesn't > > > need to > > > > > > > > > logout/login again to see the new language? > > > > > > > > > > > Best regards > > > > > > > > > Johannes- Hide quoted text - > > > > > > - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CommunityEngine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/communityengine?hl=en -~----------~----~----~----~------~----~------~--~---
