Forum: Ruby on Rails Rails coding/design input

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
668c498e13c91d6f7d6c9dbdc13ea920?d=identicon&s=25 Vivekamn Vv (vivekamn)
on 2009-05-22 07:29
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-22 10:17
(Received via mailing list)
On May 22, 6:29 am, Vivekamn Vv <rails-mailing-l...@andreas-s.net>
wrote:
>
> 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
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-05-22 10:25
(Received via mailing list)
Possibly use default_scope?

2009/5/22 Frederick Cheung <frederick.cheung@gmail.com>
This topic is locked and can not be replied to.