技術ブログ

(技術系中心)基本自分用備忘録なので、あくまで参考程度でお願いします。

resourcesをroutes.rbに追加すると。RESTfulなアクションリソースを自動作成してくれる

resourcesをroutes.rbに追加すると。RESTfulなアクションリソースを自動作成してくれる

sampleのURLを生成するための多数の名前付きルートと共に、RESTfulなsampleリソースで必要となるすべてのアクションが利用できるようになります

(routes.rb)
  resources :sample

自動作成されるルート一覧

~/w/hotspot ❯❯❯ rails routes | grep sample
WARNING: Nokogiri was built against LibXML version 2.9.7, but has dynamically loaded 2.9.4
sample_index GET    /sample(.:format)          sample#index
             POST   /sample(.:format)          sample#create
  new_sample GET    /sample/new(.:format)      sample#new
 edit_sample GET    /sample/:id/edit(.:format) sample#edit
      sample GET    /sample/:id(.:format)      sample#show
             PATCH  /sample/:id(.:format)      sample#update
             PUT    /sample/:id(.:format)      sample#update
             DELETE /sample/:id(.:format)      sample#destroy