Reputation: 18427
Is there any way I can use the :limit and :order options in the find method. I'm trying to sort activities by descending order, such that the newest activities are shown. However, when I try to use the (:all, :limit => 5, :order=> 'Date desc) I get an error. I need to limit to only 5 records, and when I disregard the order option, it works but not what I need...
Thanks
Upvotes: 3
Views: 13569
Reputation: 11385
Is your date column actually called date
? First, I would change that, date is the name of a function in most databases, that could be the cause of the error you are seeing. Rails uses created_at
, updated_at
, etc, so following that naming scheme will make your code more readable to future maintainers.
You could try to quote the column name in back-ticks:
:order => "`date` desc"
Upvotes: 0
Reputation: 641
I think you missed a quote in your example.
Model.find(:all, :limit => 5, :order=> 'created_at desc')
Make sure that a date column exists in your table.
Upvotes: 9