#76 scope_out
The scope_out plugin will generate several helpful find methods for you automatically! It's the best way to move the find conditions into your model. Watch this episode for details.
- Download:
- mp4Full Size H.264 Video (7.73 MB)
- m4vSmaller H.264 Video (5.89 MB)
- webmFull Size VP8 Video (17.4 MB)
- ogvFull Size Theora Video (9.15 MB)
Woohooo! First Comment!
I'm special :)
Great stuff, as usual. If Task had two scope outs, say "incomplete" and "ordered by name", how might you combine them when needed? I hope there's a part 2 to scope_out :-) Thanks.
Ted,
You can see how to do that on scope_out's home page
http://code.google.com/p/scope-out-rails/
I think there is a problem with the video file. I can't open it with VLC Player on PC. Could you please check it out? Thank your.
I like how you are still actively releasing new podcasts. Most of the other "programming" podcasts I came accross either have irregular updates or just stop updating all together after a relatively short period of time. July was your most active month; if you could repeat that I wouldn't complain!
anyway, fantastic podcasts. Keep up the good work.
Another great screencast, thanks Ryan!
I've been using scope_out for some time, but unfortunately every now and then, I encountered problems especially when it comes to pagination. Some time ago I wrote up a summary in my blog: http://zargony.com/2007/07/21/paginating-special-queries/
Recently I started to use the HasFinder plugin instead of scope_out. HasFinder works almost like scope_out, but it additionally gives you an easy way to arbitrarily combine scopes, like @project.tasks.incomplete.important (Task has finders :incomplete and :important). Plus it works out of the box with caching and pagination. I posted a quick summary at http://zargony.com/2007/10/20/paginating-special-queries-with-hasfinder-and-will_paginate/
HasFinder can be found at http://www.pivotalblabs.com/articles/2007/09/02/hasfinder-its-now-easier-than-ever-to-create-complex-re-usable-sql-queries
Hi there Ryan!
Long time listener first time caller! First things first, you're awesome!
OK second thing... something I've been wondering for a while is whether it's possible to extend scopes from somewhere else (e.g. a controller).
for example, in this episode you have:
scope_out :incomplete, :conditions => ['complete=?', false]
Sometimes I might want to add extra conditions when using this:
Task.find_incomplete(:all, :conditions => "rank = 'urgent'")
Do you know if there is a way to do this? maybe if you pass the conditions as a hash? (is this only available in edge rails?)
@Reza, hmm, I encoded this one the same way I do the others and it plays okay here. Are you still having a problem?
@Jonzo, you should be able to pass additional conditions in the find exactly how you do in your code. Does it not work?
@Ryan, yeah I thought it didn't work when I tried it... (specifically when using the 'conditions' variable twice) Maybe I was doing something else wrong :-O Good to know though, I'll re-visit it, Cheers :-)
Retried it and it works! I love it when I look like a crazy person... ;-)
@Ryan, I'll try to download and check it again. But there is something different with this one. The rest are playing OK in vlc player and quicktime alternative, but this one only plays on Apple Quicktime only. By the way, you are one of my personal heroes in the internet. Good job!
I was wondering how this method differs/compares to the one explain here, under "Case Three – Special Queries" (the 3'rd example):
http://www.therailsway.com/2007/3/26/association-proxies-are-your-friend
Thanks again for your casts, they've taught me a lot and I'll be sure to donate.
Nice work, again.
Have you thought about distributing these screencast files with BitTorrent?
I'm finding scope_out fails to assert key when using the :group (as in "group by") clause of find method.
Am I the only to notice this?
ArgumentError (Unknown key(s): group):
/var/lib/gems/1.8/gems/activesupport-1.4.4/lib/active_support/core_ext/hash/keys.rb:48:in `assert_valid_keys'
I have some problems using scope_out and ferret+acts_as_ferret. When I configure acts_as_ferret and try to start the server I always get an error:
(druby://localhost:9010) /....../vendor/plugins/scope_out/lib/scope_out.rb:70:in `method_missing': undefined method `aaf_configuration' for #<Class:0x251b3bc> (NoMethodError)
Does anyone experience the same problems?
I had an related problem but restarting ferret_server did help for me.