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