LoginSignup
0
0

More than 1 year has passed since last update.

一覧表示を最新の10件を表示する方法

Posted at

users/index.html.erbの一覧表示を最新10件にするコード

users_controller.eb
def index
    @resolutions = Resolution.includes(:user).order('created_at DESC').limit(10)
    @articles = Article.includes(:user).order('created_at DESC').limit(10)  
end

解説

  • order('created_at DESC')
     一覧表示を最新から表示になります
  • limit(10)
    表示10件までになります。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0