Tag: 聚合函数

如何通过ruby中的聚合函数来订购表?

我在Tender模型中有2个属性opening_date和closing_date 。 在索引页面上,我显示的是剩余日期( closing_date-Date.today )。 但是,剩余日期不会保存在数据库中,但我想按剩余日期排序并显示表中的数据。 我该怎么用? 那有一个聚合函数吗? 我使用的是Ruby 1.9.2和Rails 3.2.2 // TendersController def index @tenders= Tender.where(“company_id= ? “, current_user.company.id).order(‘closing_date’) /* Here I am querying the tender by closing_date but I dont want to do that. What I wanted is I just want to order by (closing_date-Date.today) which is not in the database but should […]