0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

rails データの並び替えまとめ

Posted at

orderの使い方がうろ覚えだったので忘備録

User.all.order(id: "DESC") # 最後から並べてくれます
User.all.order(:id)  # 指定なしなら最初から並べてくれます
User.all.order(id: "DESC").limit(3) #3件のみ表示します。多すぎる時に使うと良き。

データを見やすくするGemを入れてない時は

Gemfile
gem 'hirb'
gem 'hirb-unicode'

bundle installしやす

$bundle install

hirbを有効にしやす

$rails c
irb(main):001:0> Hirb.enable
=> true

見やすくなりましたね!mysqlで見るまでもない時にドゾー。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?