LoginSignup
0
0

More than 1 year has passed since last update.

Railsの超基本だけど忘れがちな命名規則

Last updated at Posted at 2021-06-14

投稿機能を作成していたときにめちゃくちゃつまづいてしまいした

Image from Gyazo

エラーの内容は初心者でも分かりますね。
'items_path'が定義されてないよ、'items_path'じゃない?
ってことですね。

こういう時はform_withで渡している@itemのスペルミスだったり、controllerで@itemで定義してなかったり、というのがよくあるパターンなのですが、この辺も全部やってた。

で、今回ミスっていた原因はRailsの命名規則に従ってなかったんですね。

controller名が違う!!!!!!!!

そう、対応するcontrollerを「item」で作成していたのですが、これがいけない。

controller名は複数形じゃないといけない。
一方でmodelは単数形。
ちなみにテーブルも複数形。

ということで、今回は
ルーティング、controller名とcontroller内のクラス、ビューのディレクトリ名を変更して、解決。

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