Topic: Find First Sorting


I'm trying to sort the info found by (:first) that possible? 

  has_many :dogs

  belongs_to :person

@person = Person.find_by_id(4)
@coolest_dog = @person.dogs.find(:first, order => "coolness DESC")

#Dog Table

I always get the dog with id 1 and I want to get id 3.  What am I screwing up?


Re: Find First Sorting

Yep, should be possible, but it looks like you forgot the colon to make "order" a symbol:

@coolest_dog = @person.dogs.find(:first, :order => "coolness DESC")

I'm surprised this didn't report an error.

Railscasts - Free Ruby on Rails Screencasts

Re: Find First Sorting

Stupid typos - I just typed that in since I am substituting model names to make the code more readable.  If it should work then I must have something else messed up.  I'll verify and get back if I run into problems.  Thanks as always,


Re: Find First Sorting

If it still isn't working, check out the development.log file to see the query that is getting sent to the database. Post it here if you need help understanding it.

Railscasts - Free Ruby on Rails Screencasts