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 1 year has passed since last update.

ActiveRecordのorderをハッシュで指定した際に、syntax errorが出る

Posted at

発生した問題

以下のようにRails ドキュメントに従って記述したところsyntax error出た.

Page.order(:category_id :asc)
# SELECT "pages".* FROM "pages" ORDER BY category_id ASC

解決策

以下のように直したら実行された。ドキュメントの誤植なのかもしれない。

# 動かない。rails docに書いてある方法
Page.order(:category_id :asc)

# 動く
Page.order(category_id: :asc)
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?