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.
有没有更简单和更短的方法在 Rails 中声明它?
Message.where(conditions).limit(10).order("created_at desc")
没有任何方法可以使代码更短,但是如果您想要更好的界面,可以添加范围:
Message < ActiveRecord::Base scope :my_scope, where(conditions).limit(10).order('created_at DESC') end
然后你会简单地使用查询Message.my_scope
Message.my_scope