Hi, We have a web app which serves typical social content(blogs/forums/streams etc). All the content is optionally marked with a city. I.e. if a blog post is specific to New York, it will be marked so. The task is to show only city specific information(all over the site) if user has set city view preference and show everything to all others. So I have to add ''and city == current_city'' if city_specifc_view? to all my finders in all my model classes, which is a maintenance night mare(especially as there is a risk of this logic changing). I am wondering what is the right way to apply this logic. Can I do it a central place(like overrinding the default find). Is monkey patching an option. Thanks -- Posted via http://www.ruby-forum.com/.
On May 22, 6:29 am, Vivekamn Vv <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > We have a web app which serves typical social > content(blogs/forums/streams etc). > > All the content is optionally marked with a city. I.e. if a blog post is > specific to New York, it will be marked so. > > The task is to show only city specific information(all over the site) if > user has set city view preference and show everything to all others. > > So I have to add ''and city == current_city'' if city_specifc_view? to all > my finders in all my model classes, which is a maintenance night > mare(especially as there is a risk of this logic changing). > > I am wondering what is the right way to apply this logic. Can I do it a > central place(like overrinding the default find). Is monkey patching an > option. >I think you''d be better off with a named_scope (or possibly with_scope). Fred
Possibly use default_scope? 2009/5/22 Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > > > On May 22, 6:29 am, Vivekamn Vv <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > Hi, > > > > We have a web app which serves typical social > > content(blogs/forums/streams etc). > > > > All the content is optionally marked with a city. I.e. if a blog post is > > specific to New York, it will be marked so. > > > > The task is to show only city specific information(all over the site) if > > user has set city view preference and show everything to all others. > > > > So I have to add ''and city == current_city'' if city_specifc_view? to all > > my finders in all my model classes, which is a maintenance night > > mare(especially as there is a risk of this logic changing). > > > > I am wondering what is the right way to apply this logic. Can I do it a > > central place(like overrinding the default find). Is monkey patching an > > option. > > > I think you''d be better off with a named_scope (or possibly > with_scope). > > Fred > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---