Usage: Order and: Limitations - Ruby On Rails

Is there a way I can use the limit and: order options in the find method. I am trying to sort actions in descending order so that the latest actions are displayed. However, when I try to use (: all ,: limit => 5 ,: order => 'Date desc), I get an error. I need to limit only 5 entries, and when I ignore the order option, it works, but not what I need ...

thanks

+3
source share
2 answers

I think you missed the quote in your example.

Model.find (: all ,: limit => 5 ,: order => 'created_at desc')

Make sure the date column exists in your table.

+9
source

date? -, , - , , . Rails created_at, updated_at .., .

:

:order => "`date` desc"
0

Source: https://habr.com/ru/post/1722937/


All Articles