Forum: Ruby on Rails Using with_scope with more than one model

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Db20c311ea335cbfa3ccc9e6773e3580?d=identicon&s=25 Chinmay Kulkarni (Guest)
on 2007-07-11 19:50
(Received via mailing list)
I've seen a lot of usage of with_scope since my last post, and
everywhere I
see code like this:

Mail.with_scope(:find=>{:conditions=>"user_id = ..."}) do
  count = Mail.count

Here, both the model used for scoping, and the model inside the scope is

I'm trying to do something like this:

class User<ActiveRecord::Base
  def among_friends
    User.with_scope(:find => {:conditions => friends_scope_condition})

so that I can do stuff like:
    #Find friends' quotes
                current_user.among_friends do
      @quotes_by_friends = Quote.find(:all, :order=>'created_at DESC')

Unfortunately, this doesn't work, and to correct the code, I need to use
Quote.with_scope in the among_friends definition instead.

This defeats the purpose; which was to increase flexibility.

Would appreciate any ideas.
View this message in context:
Sent from the RubyOnRails Users mailing list archive at
This topic is locked and can not be replied to.