Answer the question
In order to leave comments, you need to log in
How to sort by date on table elements in Ruby on Rails?
Suppose there is a Period model with columns (of type string) period_start and period_finish.
There are such records:
1)period_start: 01/01/2014, period_start 12/01/2014
2)period_start: 01/01/2016, period_start 12/01/2016 3)period_start: 01/01/2015
,
period_start 12/01/2015
where period_finish is newer even if period_start = 01/01/1718) came out at the beginning, and old ones at the end?
Answer the question
In order to leave comments, you need to log in
@sort = Model.all.sort_by { |d| -(d.period_finish).to_i}
Don't store in a string what can be stored as numbers. Work with data types as you need at the level of controllers, views.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question