Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个数组对象@questions,它是基于两个条件的两个活动记录查询结果的集合。@questions有一组问题及其属性。我只想通过使用基于其属性之一的排序created_at方法以降序对其进行排序。
@questions
created_at
请帮助完成这项工作:)-
我知道了。
在数组对象@questions 上有一种红宝石方法。
@questions = @questions.sort { |value1, value2| value2.created_at <=> value1.created_at }
以上对我来说很好。
试试这个
@questions = Question.order("created_at desc")