Nice tips. You don't need to apologize for anything Ryan. We appreciate every screencast you put out.
@Swami: Totally agree! Looking forward to next week's full length episode, Ryan. :)
Hey Ryan!
small and sweet screencast!!!
next week I will expect longer screencast ;)
Enjoy the holidays for now.
Time to do a screencast on spam filters for comments.. to save your Recent Comments list :)
cheers
@Adam, hah, yes. Seems spammers are executing javascript code these days. That should be the only way to post here. I'll try to clean it up soon.
Relational databases and the SQL language used to access them have no concept of "last" without an ordering. Just in case it's not clear (as it wasn't clear to me) in the Rails world, :last means "with the highest id".
I guess if you work with Rails everyday all day that :
>
Product.all(:joins => :category, :conditions => {:categories => {:name => 'Clothing'}})
makes sense, and is "easy" to remember ? ;)
This seems a lot easier to me :
clothing=Category.find_by_name("Clothing")
prods=Clothing.products
I thought that was one of the purpoes for ActiveRecord, i.e. to eliminate having to remember cryptic syntax ?
What does the first syntax do that the second one doesn't?
Mike
Or even better :
clothingProducts = Category.find_by_name('Clothing').products
Mike
@Mike
I think you missed the idea.
The extra nested hash in conditions helps you specify WHERE conditions on the associations you've joined.
I can't remember a good example right now, but quite often you need to join two or more associations, where such an addition to Rails serves to beautify code.
Like this!
:select => 'DISTINCT tracks.*',
:joins => [{:song => :stores}, {:song => :genres}],
:conditions => {:instrument_id => instrument_ids, :stores => {:id => id}, :genres => {:id => genre_ids}}
Needed to make a simple search feature work.
What I don't understand is why this works and yet :include doesn't. If you try to use includes you get outer joins but it also ignores the select.
Great episode. How to handle spam comments would be a great topic too.
@Mike
Your answer may seem easier but you missed that with your sentences you end up making 2 queries while it was originally only one.
By the way, I'd like to understand it too, PhilT! You can give a try to a really nice pluggin about writing "rubyish" queries: Squirrel (http://thoughtbot.com/projects/squirrel)
Did you know, that content_tag is more slover than static tag definition like "<div>#{@hello}</div>"?
Oh, Paypal codes!! This blog just loves Paypal and i hate it and wiped its codes off my sites long time ago!
Excellent, as always. I took your tutorial (from episode 40 as well) and made it more customizable. I wanted to share it with everyone (note this is not heavily tested!):
See my blog post:
http://railshacks.blogspot.com/2009/02/blocks-in-view.html
or dive straight into the code:
http://pastie.org/383089





