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
  • 相关阅读:
    简单优化:Zipalign
    Using lists in Android (ListView)
    6410移植RT3070无线模块,WPA加密方式,并开机自动加载
    html表格的动态增加删除
    html 中表格长度固定
    跨域 Iframe 通信解决方案(兼容 IE 系列浏览器。)
    Sass 基础和入门
    javascript 模块化编程 1
    Canvas的方法覆盖和实现新的API
    获取鼠标点击相对于Canva位置的2种方法
  • 原文地址:https://www.cnblogs.com/SoulSpirit/p/3421865.html
Copyright © 2011-2022 走看看