This project is archived and is in readonly mode.
Improved named_scope to be used like as with_scope
Reported by Genki Takiuchi | August 1st, 2008 @ 10:53 AM | in 2.x
named_scope is really cool feature of the latest Ruby on Rails, but it can't be used with good old with_scope.
So I implemented "with" method to the Scope class so that we can use a scoped block like this:
User.active.with do
User.count #=> equals to User.active.count
end
Comments and changes to this ticket
-
Ryan Bates August 1st, 2008 @ 06:07 PM
I just needed this functionality not too long ago, and the implementation looks nice and simple. However, it looks like tests are missing, could you add some?
-
Ryan Bates August 1st, 2008 @ 08:42 PM
- no changes were found...
-
Ryan Bates August 1st, 2008 @ 08:42 PM
I've been playing around with this a little bit and found out you can completely remove the "with" method on the Scope class and it will still behave properly. This is because when you call "with" it will be delegated to the proxy scope and already apply with_scope.
I propose not using the "with" method at all and just sticking to with_scope. This required a couple minor changes but I've attached a patch which does this.
User.active.with_scope do User.count #=> equals to User.active.count end
-
Pratik August 22nd, 2008 @ 04:13 AM
- State changed from new to wontfix
This is not very with_scope like as with_scope was made a private method after people started abusing it in around_filter, which is against Rails way of doing things.
This should still work, however it should be a protected method.
Might be a good idea to discuss in the mailing list.
Thanks.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>