LoginSignup
6
5

More than 5 years have passed since last update.

railsのルーティングの不思議

Posted at

疑問

railsのルーティングを次のように行うと、

routes.rb
resources :aws, only: [:index]
resources :openstack, only [:index]

次のようになった。

         Prefix Verb URI Pattern             Controller#Action
            aws GET /aws(.:format)           aws#index
openstack_index GET /openstack(.:format)     openstack#index

Prefixのawsとopenstack_indexの違いが気になった。
「_index」はどこから来たのか。

答え

railsではリソースは複数形で記述するらしい。
単数形で記述した場合、Prefixの後ろにindex, showなどのactionが追加されるっぽい。

試してみた

いろんな単語で試してみた。

routes.rb
resources :miss, only: [:index]
resources :misses, only: [:index]
resources :man, only: [:index]
resources :men, only: [:index]
resources :tea, only: [:index]
         Prefix Verb URI Pattern             Controller#Action
           miss_index GET /miss(.:format)    miss#index
               misses GET /misses(.:format)  misses#index
            man_index GET /man(.:format)     man#index
                  men GET /men(.:format)     men#index
            tea_index GET /tea(.:format)     tea#index

結果

awsはAmazon Web Servicesの略なので複数形扱い。
複数形が変則的な名詞にも対応してるっぽい。
不可算名詞は単数形扱い。

辞書みたいなものを参照してるのかな?

6
5
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
6
5