Token导航 LogoToken导航

Agent Skill · 研究检索

routing-patterns(路由模式)

routing-patterns 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

routing-patterns 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 50,488。

总安装 612周安装 26GitHub Stars 5下载 214核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:routing-patterns(路由模式)
来源仓库:https://github.com/rolemodel/rolemodel-skills
仓库路径:skills/routing-patterns
安装命令:
npx skills add https://github.com/rolemodel/rolemodel-skills --skill routing-patterns
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/rolemodel/rolemodel-skills --skill routing-patterns

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

routing-patterns 用于查找、检索和筛选相关信息。适合在关键词、任务场景或来源线索下快速定位候选结果。

安装命令:npx skills add https://github.com/rolemodel/rolemodel-skills --skill routing-patterns 适用于 Codex、Claude、Cursor、Gemini CLI,通过 GitHub 安装,建议确认权限范围和维护状态。

可能触发联网、命令执行或文件读写,使用前请核实具体行为。

来源仓库内路径:skills/routing-patterns

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/rolemodel/rolemodel-skills --skill routing-pat…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

routing-patterns 怎么安装?

在终端执行 npx skills add https://github.com/rolemodel/rolemodel-skills --skill routing-patterns。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

routing-patterns 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

routing-patterns 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

routing-patterns 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

routing-patterns 用的人多吗?

公开数据是累计安装 612 次,近一周安装 26 次,下载 214 次,GitHub 5 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

routing-patterns 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
routing-patterns

路由模式 · 本页

6125需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Routes Best Practices

Purpose

This skill helps AI agents review, generate, and update Rails routes following professional patterns and best practices. It covers RESTful resource routing, route concerns for code reusability, shallow nesting strategies, and advanced route configurations that can be applied to any Rails application.

Context

This skill covers:

  • Rails routing with RESTful conventions
  • Route concerns for DRY (Don't Repeat Yourself) principle
  • Shallow nesting to avoid overly long URLs
  • Custom parameters and metadata for flexible routing
  • Custom route resolvers for polymorphic paths
  • Constraint-based routing for authorization
  • Organization patterns for maintainable routes files

Best Practices

1. Route Concerns for Reusable Behavior

Define concerns at the top of routes.rb for behaviors shared across multiple resources. This keeps your routes DRY and maintainable.

Example: Commentable Resources

concern :commentable do
  resources :comments, commentable_type: parent_resource.name.classify
end

Example: Duplicatable Resources

concern :duplicatable do
  resources :duplications, only: %i[create], resource_type: parent_resource.name.classify
end

Example: Dynamic Form Updates (Turbo/AJAX)

concern :turbo_fetch do
  patch :turbo_fetch, on: :collection
end

Key Points:

  • Concerns extract common nested resource patterns into reusable modules
  • Use parent_resource.name.classify to dynamically pass the parent context type to controllers
  • Specify only: or except: to limit actions when appropriate
  • Custom parameters (like commentable_type, resource_type) are passed as metadata to controllers
  • Controllers can access these via params[:commentable_type] or routing metadata

2. Applying Concerns to Resources

Apply concerns using the concerns: option with an array of symbols:

resources :products, concerns: %i[duplicatable turbo_fetch]
resources :articles, concerns: %i[commentable duplicatable turbo_fetch]

Benefits:

  • Eliminates repetitive nested resource definitions
  • Changes to shared behavior only need to be updated in one place
  • Makes it immediately clear which resources share common functionality

3. Shallow Nesting Strategy

Use scope shallow: true wrapper to enable shallow nesting for all nested resources. This prevents URLs from becoming unwieldy with deep nesting.

scope shallow: true do
  resources :projects do
    resources :tasks do
      resources :comments
        # comments routes are shallow - only :index and :create are nested
        # show/edit/update/destroy use /comments/:id instead of /projects/:project_id/tasks/:task_id/comments/:id
      end
    end
  end
end

Benefits:

  • Shorter, cleaner URLs for member actions (show, edit, update, destroy)
  • Only collection actions (index, create) remain nested under parent
  • Easier to bookmark and share individual resource URLs
  • Can override with shallow: false when full nesting is needed

Generated Routes:

# Nested (collection routes)
GET    /projects/:project_id/tasks                tasks#index
POST   /projects/:project_id/tasks                tasks#create
GET    /projects/:project_id/tasks/new            tasks#new

# Shallow (member routes)
GET    /tasks/:id                                 tasks#show
GET    /tasks/:id/edit                            tasks#edit
PATCH  /tasks/:id                                 tasks#update
DELETE /tasks/:id                                 tasks#destroy

Override Example:

concern :assembly do
  # Keep full nesting when parent context is always needed
  resources :assembly_items, only: %i[show], param: :kind, shallow: false
end

4. Limiting Actions with only: and except:

Always be explicit about which actions a resource provides. This improves security, performance, and code clarity.

# Only specific actions
resources :webhooks, only: [], concerns: %i[turbo_fetch]  # No standard REST actions, only custom
resources :duplications, only: %i[create]                 # Only create action needed
resources :previews, only: %i[show update]                # Only show and update

# All except specific actions
resources :automations, except: %i[show]                  # All standard actions except show
resources :notes, except: %i[show]                        # Create/edit/destroy but no individual view
resources :widgets, except: %i[index show]                # No collection or individual views

Why This Matters:

  • Prevents unused routes from cluttering rails routes output
  • Blocks access to unimplemented controller actions
  • Documents intent clearly for other developers
  • Reduces attack surface by not exposing unnecessary endpoints

5. Nested Resources

For resources that belong to a parent, nest them appropriately:

resources :companies do
  resources :employees, except: %i[index show]
end

resources :products do
  resources :reviews, except: %i[index]
  resources :variants, except: %i[index show]
end

Common Pattern:

  • Parent resource gets full CRUD by default
  • Nested resources often exclude index (displayed on parent's show page)
  • Nested resources often exclude show (edited inline or from parent view)
  • Nested create/update/destroy actions work within parent context

6. Singular Resources

Use resource (singular) for resources where there's only one per parent:

resources :users do
  resource :profile, only: %i[show edit update]  # Only one profile per user
  resource :settings, only: %i[edit update]      # Only one settings per user
  resource :avatar, only: %i[show update]        # Only one avatar per user
end

Key Points:

  • Singular resources don't have an index action
  • URLs don't require an :id parameter (e.g., /users/1/profile not /users/1/profiles/1)
  • Perfect for one-to-one relationships or singleton resources

7. Collection and Member Routes

Add custom routes using on::collection or on::member:

resources :products do
  # Collection routes (no :id needed)
  get :search, on: :collection              # /products/search
  post :bulk_import, on: :collection        # /products/bulk_import

  # Member routes (requires :id)
  post :duplicate, on: :member              # /products/:id/duplicate
  patch :archive, on: :member               # /products/:id/archive
  get :preview, on: :member                 # /products/:id/preview
end

# In a concern
concern :archivable do
  patch :archive, on: :member
  patch :unarchive, on: :member
end

Key Points:

  • Collection routes act on the entire collection (no :id parameter)
  • Member routes act on a single resource (requires :id parameter)
  • Use appropriate HTTP verbs (GET for reads, POST for creates, PATCH/PUT for updates, DELETE for removes)

8. Custom Parameters

Override default parameter names using param::

resources :products, param: :slug  # Uses :slug instead of :id

# In concerns
concern :categorizable do
  resources :categories, only: %i[show], param: :slug
end

Results:

  • URLs become /products/:slug instead of /products/:id
  • Controller receives params[:slug] instead of params[:id]
  • Example: /products/vintage-leather-jacket instead of /products/123
  • Useful for SEO-friendly URLs or when using non-numeric identifiers

9. Default Options

Set default options for a resource:

resources :categories, defaults: { subcategory: false }

These defaults are available in params[:subcategory].

10. Custom Route Resolvers

Define custom resolvers for polymorphic path helpers:

resolve 'Bulk::Accessories' do |form|
  form.persisted? ? [form.accessory] : [form.tank, :accessories]
end

resolve 'AssemblyItem' do |item|
  [item.host, item]
end

Usage: These allow url_for(@form_object) or link_to(@assembly_item) to work correctly.

11. Session Routes

Use controller block with scope for related authentication actions:

controller :sessions do
  get :login, action: :new
  delete :logout, action: :destroy

  scope :auth do
    get :failure
    match 'ADFS/callback', action: :create, via: %i[get post], as: :adfs_callback
  end
end

12. Mounting Engines with Constraints

Mount admin engines with authentication constraints:

# Allow access only if user is logged in and is admin
mount PgHero::Engine, at: :pghero,
  constraints: -> env {
    env.session[:user_id].present? &&
    User.find_by(id: env.session[:user_id])&.admin?
  }

# Redirect to login if not authenticated
get :pghero, to: redirect('/login'), anchor: false,
  constraints: -> env { env.session[:user_id].blank? }

13. Health Check Routes

# Production health check
mount Health::Check::Engine, at: 'health-check' if Rails.env.production?

# Rails 7.1+ health check
get :up, to: 'rails/health#show', as: :rails_health_check

Complete Example Structure

Here's a well-organized routes file following all best practices:

Rails.application.routes.draw do
  # 1. Define concerns first (reusable route patterns)
  concern :commentable do
    resources :comments, commentable_type: parent_resource.name.classify
  end

  concern :archivable do
    patch :archive, on: :member
    patch :unarchive, on: :member
  end

  concern :searchable do
    get :search, on: :collection
  end

  # 2. Main routes with shallow nesting
  scope shallow: true do
    # Top-level resources
    resources :users, except: %i[show] do
      resource :profile, only: %i[show edit update]
      resource :settings, only: %i[edit update]
    end

    resources :products, concerns: %i[commentable archivable searchable] do
      resources :reviews, except: %i[index]
      resources :variants, except: %i[index show]
    end

    # Nested resources
    resources :projects do
      resources :tasks, concerns: %i[commentable] do
        resource :assignment, only: %i[create destroy]
      end
    end
  end

  # 3. Session/authentication routes
  controller :sessions do
    get :login, action: :new
    post :login, action: :create
    delete :logout, action: :destroy
  end

  # 4. Admin routes with constraints
  namespace :admin do
    resources :users
    resources :settings, only: %i[index update]
  end

  # 5. Mounted engines (with constraints if needed)
  mount Sidekiq::Web, at: '/sidekiq', constraints: AdminConstraint.new

  # 6. Custom route resolvers (for polymorphic routing)
  resolve 'ProjectTask' do |task|
    [task.project, task]
  end

  # 7. Health checks
  get :up, to: 'rails/health#show', as: :rails_health_check

  # 8. Root route
  root 'dashboard#index'
end

Review Checklist

When reviewing or generating routes, verify:

  • Concerns are defined at the top of the file
  • Concerns are DRY and reusable across multiple resources
  • Custom parameters (like commentable_type) use parent_resource.name.classify
  • Shallow nesting is enabled with scope shallow: true
  • Resources explicitly use only: or except: to limit actions
  • Nested resources follow the pattern (often no index/show)
  • Singular resources use resource not resources
  • Collection/member routes use on: parameter
  • Custom parameter names use param: when needed
  • Route resolvers are defined for form objects and polymorphic models
  • Admin engines have authentication constraints
  • Root route is defined
  • Routes are organized logically (concerns → resources → custom → engines → resolvers → root)

Anti-Patterns to Avoid

❌ Don't repeat nested resource patterns:

resources :articles do
  resources :comments, commentable_type: 'Article'
end

resources :posts do
  resources :comments, commentable_type: 'Post'
end

✅ Use concerns instead:

concern :commentable do
  resources :comments, commentable_type: parent_resource.name.classify
end

resources :articles, concerns: %i[commentable]
resources :posts, concerns: %i[commentable]

❌ Don't use deep nesting without shallow:

resources :companies do
  resources :projects do
    resources :tasks do
      # Results in /companies/:company_id/projects/:project_id/tasks/:id/edit
    end
  end
end

✅ Use shallow nesting:

scope shallow: true do
  resources :companies do
    resources :projects do
      resources :tasks  # edit becomes /tasks/:id/edit
    end
  end
end

❌ Don't leave all actions when not needed:

resources :duplications  # Provides 7 REST actions but only need create

✅ Be explicit:

resources :duplications, only: %i[create]

❌ Don't use plural for singular resources:

resources :profiles, only: %i[show]  # There's only one profile per user

✅ Use singular resource:

resource :profile, only: %i[show]

❌ Don't hardcode context types:

concern :commentable do
  resources :comments, commentable_type: 'Article'  # Only works for articles
end

✅ Use parent_resource:

concern :commentable do
  resources :comments, commentable_type: parent_resource.name.classify
end

Advanced Patterns

Concerns with Nested Concerns

Concerns can reference other concerns for highly reusable routing patterns:

concern :searchable do
  get :search, on: :collection
  get :autocomplete, on: :collection
end

concern :taggable do
  resources :tags, only: %i[index create destroy],
    concerns: %i[searchable],
    taggable_type: parent_resource.name.classify
end

resources :articles, concerns: %i[taggable]
# Articles get tags with search and autocomplete functionality

Multiple Custom Params

You can pass multiple custom parameters to concerns:

concern :versioned do
  resources :versions,
    only: %i[index show],
    param: :version_number,
    shallow: false,
    versionable_type: parent_resource.name.classify
end

These custom parameters are available in the controller as routing metadata:

# In controller
def index
  @versionable_type = request.path_parameters[:versionable_type] # => "Article"
end

Context-Specific Route Additions

Add additional routes to specific resources after applying a concern:

resources :articles, concerns: %i[commentable] do
  # Add article-specific routes beyond the concern
  get :preview, on: :member
  post :publish, on: :member
end

Conditional Engine Mounting

Mount engines conditionally based on environment:

if Rails.env.production?
  mount HealthCheck::Engine, at: 'health-check'
end

unless Rails.env.production?
  mount LetterOpenerWeb::Engine, at: '/letter_opener'
end

Common Routing Patterns

These patterns appear frequently in Rails applications and can be implemented using concerns:

Commentable Resources:

  • Pattern: Resources that can have comments
  • Implementation: Nested comments resource with polymorphic association
  • Applied to: Articles, blog posts, products, tasks, etc.

Duplicatable Resources:

  • Pattern: Resources that can be cloned/duplicated
  • Implementation: Create-only nested resource for duplication action
  • Applied to: Templates, documents, configurations, etc.

Archivable Resources:

  • Pattern: Resources that can be archived/unarchived
  • Implementation: Member routes for archive state changes
  • Applied to: Projects, documents, records, etc.

Searchable Resources:

  • Pattern: Resources with search/filter functionality
  • Implementation: Collection routes for search operations
  • Applied to: Products, users, articles, etc.

Versioned Resources:

  • Pattern: Resources with version history
  • Implementation: Nested versions resource, often read-only
  • Applied to: Documents, API resources, configurations, etc.

Taggable Resources:

  • Pattern: Resources that can be tagged/categorized
  • Implementation: Nested tags with create/destroy actions
  • Applied to: Articles, images, bookmarks, etc.

Usage Instructions for AI Agents

When asked to review routes:

  1. Check routes are organized: concerns → resources → custom → engines → resolvers → root
  2. Verify concerns are properly defined and reusable
  3. Check for deep nesting that should use shallow
  4. Ensure resources use only:/except: appropriately
  5. Verify singular vs plural resource usage
  6. Check for repeated patterns that should be concerns
  7. Validate custom resolvers match model relationships

When asked to generate new routes:

  1. Determine if the behavior is reusable → create/use a concern
  2. Check if resource should be nested under a parent
  3. Enable shallow nesting for nested resources (unless explicitly needed)
  4. Specify only: or except: based on needed actions
  5. Use resource (singular) if there's only one per parent
  6. Add custom collection/member routes if needed
  7. Create route resolver if it's a form object or polymorphic model
  8. Follow existing concern patterns for similar functionality

When asked to update routes:

  1. Maintain consistency with existing patterns
  2. If adding similar functionality to multiple resources, refactor to use concerns
  3. Update existing concerns rather than duplicating code
  4. Preserve shallow nesting strategy
  5. Keep routes organized in the established structure
  6. Update custom resolvers if model relationships change

Testing Routes

Always verify routes after changes:

# List all routes
rails routes

# Search for specific routes
rails routes | grep products

# Show routes for a specific controller
rails routes -c products

# Show routes with expanded format
rails routes --expanded

# Filter by HTTP verb
rails routes -g POST

*Last Updated: February 2026*

平台分布

Codex

37.23%
按下载量换算80

Claude

27.09%
按下载量换算58

Cursor

19.56%
按下载量换算42

Gemini CLI

9.16%
按下载量换算20

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills