jeudi 29 juin 2017

Order a model with conditions in Rails (3)

Lets say there is a model called Event. I want to display important and current events first, so i have the attributes important (boolean) and enddate (date).

Now I want to get all events where important == true and where enddate >= today first, all others should be ordered by created_at.

I want to avoid doing events = important_events + not_important_events as this would return an array insted of an activerecord. Does anyone knows an elegant way to order a model in rails?

Aucun commentaire:

Enregistrer un commentaire