ruby on rails(七) 路由

  • member,添加成員路由,只需在 resource 塊中添加 member 塊:
resources :nodes do
    member do
      post :block
    end
  end

Rails 路由能夠識(shí)別 /nodes/1/block 路徑上的 POST 請(qǐng)求

  • collection
resource :uers, controller: 'uers' do
    collection do
      get :login
    end
 end

Rails 路由能夠識(shí)別 /uers/login 路徑上的 GET 請(qǐng)求

  • namespace 與 scope
    namespace聲明路由信息:
namespace :blog do
   resources :contexts
end

生成的路由信息如下:

 blog_contexts GET    /blog/contexts(.:format)          {:action=>"index", :controller=>"blog/contexts"}
                  POST   /blog/contexts(.:format)          {:action=>"create", :controller=>"blog/contexts"}
 new_blog_context GET    /blog/contexts/new(.:format)      {:action=>"new", :controller=>"blog/contexts"}
edit_blog_context GET    /blog/contexts/:id/edit(.:format) {:action=>"edit", :controller=>"blog/contexts"}
     blog_context GET    /blog/contexts/:id(.:format)      {:action=>"show", :controller=>"blog/contexts"}
                  PUT    /blog/contexts/:id(.:format)      {:action=>"update", :controller=>"blog/contexts"}
                  DELETE /blog/contexts/:id(.:format)      {:action=>"destroy", :controller=>"blog/contexts"}

而scope則如下:

scope :module => 'blog' do
   resources :contexts
end

生成的路由如下:

 contexts GET    /contexts(.:format)           {:action=>"index", :controller=>"blog/contexts"}
              POST   /contexts(.:format)           {:action=>"create", :controller=>"blog/contexts"}
  new_context GET    /contexts/new(.:format)       {:action=>"new", :controller=>"blog/contexts"}
 edit_context GET    /contexts/:id/edit(.:format)  {:action=>"edit", :controller=>"blog/contexts"}
      context GET    /contexts/:id(.:format)       {:action=>"show", :controller=>"blog/contexts"}
              PUT    /contexts/:id(.:format)       {:action=>"update", :controller=>"blog/contexts"}
              DELETE /contexts/:id(.:format)       {:action=>"destroy", :controller=>"blog/contexts"}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 9,039評(píng)論 0 6
  • ¥開(kāi)啟¥ 【iAPP實(shí)現(xiàn)進(jìn)入界面執(zhí)行逐一顯】 〖2017-08-25 15:22:14〗 《//首先開(kāi)一個(gè)線(xiàn)程,因...
    小菜c閱讀 7,295評(píng)論 0 17
  • 參考 RailsGuides中的Rails Routing from the Outside In 簡(jiǎn)介 Rail...
    零小白閱讀 7,553評(píng)論 0 15
  • 夏天的傍晚,我總是約老馬一起去踢球,過(guò)去的幾個(gè)暑假都是這樣,因?yàn)槲液屠像R雙雙落榜。在此之前,我和老馬互相嗤...
    深藍(lán)小熊閱讀 571評(píng)論 2 1

友情鏈接更多精彩內(nèi)容