How to order a table by aggregate function in a ruby?
问题 I have 2 attributes opening_date and closing_date in a Tender model. On the index page what I display is the remaining date which is ( closing_date-Date.today ). However, remaining date is not saved in a database but I wanted to order and display the data in the table by remaining date. What should I use? Is there an aggregate function for that? I am using Ruby 1.9.2 and Rails 3.2.2 //TendersController def index @tenders= Tender.where("company_id= ? ", current_user.company.id).order('closing