LoginSignup
4
3

More than 1 year has passed since last update.

RailsのPrefix名がおかしくなった件

Last updated at Posted at 2020-01-14

環境

Ruby 2.6.4
Rails 5.2.3

経緯

ライブ関係のアプリをつくろうとして、以下のようなルーティングを設定。

routes.rb
Rails.application.routes.draw do
  resources :lives
end

そして、ルーティングを確認したら、なぜかlifeになってしまった!
スクリーンショット 2020-01-14 17.25.54.png

原因

Railsで勝手に単数形のPrefixを割り振ってしまったため。
https://ejje.weblio.jp/content/life
スクリーンショット 2020-01-14 17.30.02.png

解決方法

ルーティングを以下のようにして解消しました。

routes.rb
Rails.application.routes.draw do
  resources :lives, only: :index
  resources :lives, as: :live, except: :index
end

スクリーンショット 2020-01-14 17.46.09.png

live_indexだけ気になりますね。。。
これについてはこちらの記事を一読ください。

4
3
1

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