国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Ruby > 正文

關于Ruby on Rails路由配置的一些建議

2020-10-29 19:37:25
字體:
來源:轉載
供稿:網友

當你需要加入一個或多個動作至一個 RESTful 資源時(你真的需要嗎?),使用 member and collection 路由。

  # 差  get 'subscriptions/:id/unsubscribe'  resources :subscriptions  # 好  resources :subscriptions do   get 'unsubscribe', on: :member  end  # 差  get 'photos/search'  resources :photos  # 好  resources :photos do   get 'search', on: :collection  end

    若你需要定義多個 member/collection 路由時,使用替代的區塊語法(block syntax)。

  

 resources :subscriptions do   member do    get 'unsubscribe'    # 更多路由   end  end  resources :photos do   collection do    get 'search'    # 更多路由   end  end

    使用嵌套路由(nested routes)來更佳地表達與 ActiveRecord 模型的關系。

  

 class Post < ActiveRecord::Base   has_many :comments  end  class Comments < ActiveRecord::Base   belongs_to :post  end  # routes.rb  resources :posts do   resources :comments  end

    使用命名空間路由來群組相關的行為。

  namespace :admin do   # Directs /admin/products/* to Admin::ProductsController   # (app/controllers/admin/products_controller.rb)   resources :products  end

    不要在控制器里使用留給后人般的瘋狂路由(legacy wild controller route)。這種路由會讓每個控制器的動作透過 GET 請求存取。

  # 非常差  match ':controller(/:action(/:id(.:format)))'


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衡水市| 涿鹿县| 海原县| 波密县| 石渠县| 平邑县| 临夏市| 慈利县| 濮阳县| 章丘市| 博客| 日照市| 绥阳县| 岑溪市| 腾冲县| 横山县| 尚义县| 定日县| 凉山| 高陵县| 通化县| 新绛县| 泽库县| 陆丰市| 盐亭县| 绍兴市| 莫力| 桂阳县| 永胜县| 黄龙县| 岑巩县| 皋兰县| 晋宁县| 原阳县| 浦县| 高雄县| 巴东县| 繁峙县| 颍上县| 玉屏| 出国|