zoukankan      html  css  js  c++  java
  • 手把手教你学习ROR-6.Rooter的配置

    Router的好处

    1 能使你的URL更符合REST规范,而不是带着参数的URL

    2 能让你的View使用Path,而不是直接硬编码

    3 统一放置,方便管理

    Router,View的对用关系

    GET /photos index display a list of all photos photos_path 
    GET /photos/new new return an HTML form for creating a new photo new_photo_path
    POST /photo create create a new photo photo_path 
    GET /photos/:id show display a specific photo photo_path(@photo)
    GET /photos/:id/edit edit return an HTML form for editing a photo edit_photo_path(@photo)
    PATCH/PUT /photos/:id update update a specific photo photo_path(@photo)
    DELETE /photos/:id destroy delete a specific photo photo_path(@photo)

    Router的使用

    A: NameSpace

    namespace :group do

      resources :articles
    end
     
    这里使用Group::ArticleController,而路径/group/article/:id之类的group_articles_path
     
    B: Scope
    scope '/admin' do
      resources :posts, :comments
    end
     
    这里使用ArticleController,路径/group/article/:id之类的
     
    C: Module
    resources :articles, module: 'group'
     
    same with;

    scope module: 'group' do
    resources :articles
    end

    这里使用Group::ArticleController,路径/article/:id之类的
     
    D:嵌套

    resources :magazines do
      resources :ads
    end

    这里使用 AdsController,路径/magazines/:magazine_id/ads,magazine_ads_url

    E: Concern

    concern :commentable do

      resources :comments
    end
     
    resources :messages, concerns: :commentable
    这里使用CommentsController,路径/messages/:message_id/comments
     
    F: Shallow
  • 相关阅读:
    求第N个素数
    HDU1568
    HDU1003 DP
    POJ 1016 模拟字符串
    POJ 3321 树状数组(+dfs+重新建树)
    UVA12532 线段树(单点更新,区间求乘积的正负)
    POJ2488 dfs
    POJ 1195 二维树状数组
    HDU 4006 优先队列
    优先队列
  • 原文地址:https://www.cnblogs.com/SoulSpirit/p/3421865.html
Copyright © 2011-2022 走看看