On 27 August 2010 15:19, Dakshata Gulkhobare <[email protected]> wrote:
> car_price = UsedCar.find(:all, :order => 'price DESC' )

That will give you them all in descending price order so the first one
will be the most expensive.  You could have called it cars rather than
car_price to indicate that it is an array (or similar) of Cars.  If
you want them in price increasing you can say

cars = UsedCar.find(:all, :order => :price)
or to get just the cheapest
cheapest_car = UsedCar.find(:all, :order => :price).first

>
>  puts "#{car_price[0]}"

puts car_price[0] would have done the same thing.

>
>
> I used the above syntax and it o/p s it as
>
>
> merjis-mac-mini:seed_trademark dakshata$ rake db:seed
> (in /Users/dakshata/source/learning-ruby/seed_trademark)
> #<UsedCar:0x1a08628>

If you want to see the individual fields then you need
cheapest_car.make and so on.
Why are you doing it in db:seed by the way?

Have a look at the Rails Guides at http://guides.rubyonrails.org/.
They are very useful.  If you are following any tutorials make sure
they are for Rails 2.3 assuming that is what you are using.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to