LoginSignup
1
4

More than 5 years have passed since last update.

ActiveRecord::StatementInvalid in Tasks#index

Posted at

ActiveRecord::StatementInvalid in Tasks#index

「現場で使える Ruby on Rails 5速習実践ガイド」
の7章をやっていて以下のエラーが出た。

Showing /home/ubuntu/rql/taskleaf/app/views/tasks/index.html.slim where line #21 raised:

PG::UndefinedColumn: ERROR:  column "craeted_at" does not exist
LINE 1: ...ROM "tasks" WHERE "tasks"."user_id" = $1 ORDER BY "craeted_a...
                                                             ^
HINT:  Perhaps you meant to reference the column "tasks.created_at".
: SELECT DISTINCT "tasks".* FROM "tasks" WHERE "tasks"."user_id" = $1 ORDER BY "craeted_at" DESC

というエラーが出た。
データベースがおかしい(上記のcraeted_atという打ち間違い)のかと思い、コンソールでテーブル、カラムを出力しても打ち間違いは見当たらない。。。

結果どこが間違っているのかと言うとモデルのscopeだった

task.rb
scope :recent, -> { order(craeted_at: desc)}

ここを修正すると問題なく動作。
エラー画面からここまでたどり着くのに結構時間かかった。。。。

1
4
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
1
4