I have in my model
class Card < ActiveRecord::Base has_many :idioms, dependent: :destroy end
class Idiom < ActiveRecord::Base belongs_to :card end
In my schema, Idiom has an integer column kind. Given a certain card, I would like to have all associated idioms, but sorted in descending order according to the 'kind' column.
I could do a
@card.idioms.sort { .... }
but would prefer doing the sorting by the time the data is retrieved from the database. I googled two suggestions:
(1) @card.idioms(:order => 'kind DESC')
This doesn't seem to have any effect.
(2) @card.idioms.all(:order => 'kind DESC')
This gives the error "wrong number of arguments (1 for 0)".
I think I could do a
Idiom.where(....)
and put an order restriction there, but I feel that Rails must have a way to specify sorting when following associations, and maybe I just made some silly mistake. Any ideas?