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 5 years have passed since last update.

rails g scaffold_controllerしたのに、indexにアクセスするとNo route matches

Posted at

発生したこと

rails g scaffold_controller crazy_diamondやりました。
コントローラーとかviewとかできました。

create  app/controllers/crazy_diamonds_controller.rb
invoke  erb
create    app/views/crazy_diamonds
create    app/views/crazy_diamonds/index.html.erb
create    app/views/crazy_diamonds/edit.html.erb
create    app/views/crazy_diamonds/show.html.erb
create    app/views/crazy_diamonds/new.html.erb
create    app/views/crazy_diamonds/_form.html.erb

そんで、http://localhost:3000/crazy_diamondsにアクセスしました。
image.png

なんでか。

解決策

参考:https://mpiyok.hatenablog.com/entry/2015/10/05/074742

config/routes.rb
Rails.application.routes.draw do

  resource :crazy_diamonds  # indexはルーティングされない
  resources :crazy_diamonds # indexがルーティングされる

「resource」に「s」がつてないと。だからindexにはアクセスできませんと。
ドヤ顔でミスを指摘してくるバイトリーダーを思い出しました。

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?