設定RESTful路由

resources :photos加/config/routes.rb檔案中即可。

  
    Rails.application.routes.draw do
      <span class="com"># For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html</span>

      resources :photos

    end
  

確認路由設定結果

使用rails routes指令來確認路由設定是否成功。如果成功將會出現以下畫面。

  
                         Prefix   Verb      URI Pattern                             Controller#Action
                   <span class="point">DB name</span>   GET       /<span class="point">DB name</span>(.:format)               photos#index
                                     POST     /<span class="point">DB name</span>(.:format)               photos#create
    new_<span class="point">Model name</span>   GET       /<span class="point">DB name</span>/new(.:format)       photos#new
    edit_<span class="point">Model name</span>   GET       /<span class="point">DB name</span>/:id/edit(.:format)  photos#edit
             <span class="point">Model name</span>   GET       /<span class="point">DB name</span>/:id(.:format)          photos#show
                                     PATCH  /<span class="point">DB name</span>/:id(.:format)          photos#update
                                     PUT       /<span class="point">DB name</span>/:id(.:format)          photos#update
                                     DELETE /<span class="point">DB name</span>/:id(.:format)          photos#destroy