Ruby Rails

mindrally/skills/ruby-rails

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Conventions and best practices for building web applications with Ruby on Rails. Use when scaffolding Rails apps or generators, designing ActiveRecord models and migrations, wiring up Hotwire/Turbo/Stimulus interactivity, setting up background jobs or caching, or writing RSpec/Minitest coverage for Rails code.

AI 產生的概覽

提供建構 Ruby on Rails 網頁應用程式的慣例與最佳實務,涵蓋模型、遷移、Hotwire、背景工作與測試。

功能
提供符合 Ruby 與 Rails 慣例的指引,包括命名規範、MVC 架構、ActiveRecord 建模、索引、預先載入與快取。內容涵蓋 Rails 8 預設元件,例如 Solid Queue、Solid Cache、Solid Cable、Propshaft 與 Kamal,以及使用 Hotwire、Tailwind CSS 和 ViewComponents 的前端整合。也涉及安全實務,例如強參數、CSRF 防護與身分驗證,以及使用 Minitest 或 RSpec、FactoryBot 和 TDD 的測試方法。
適用情境
適用於建立 Rails 應用程式或產生器、設計 ActiveRecord 模型與遷移、串接 Hotwire/Turbo/Stimulus 互動、設定背景工作或快取,以及為 Rails 程式碼撰寫 RSpec/Minitest 測試。適合希望遵循框架慣例與最佳實務的 Rails 開發者。它本身不會執行指令或產生檔案。
執行需求
不需要腳本或工具,僅為說明性內容。若要實踐其中建議,需要 Ruby on Rails 專案、Ruby 3.x、PostgreSQL 等資料庫,以及可選的測試與前端函式庫,例如 RSpec、Minitest、FactoryBot、Hotwire、Tailwind CSS 和 ViewComponents。

Ruby on Rails

This skill covers Ruby and Ruby on Rails development, including Rails conventions, ActiveRecord patterns, frontend integration, security, and testing.

Core Principles

  • Write concise, idiomatic Ruby code with accurate examples
  • Adhere to Rails conventions (Convention over Configuration)
  • Follow the Ruby Style Guide for formatting consistency
  • Leverage Ruby 3.x features like pattern matching and endless methods
  • Prefer Rails command-line generators (bin/rails generate ...) over hand-written boilerplate — they keep files consistent with framework conventions and wire up tests/routes automatically
  • Use bin/dev to run the local development server (it boots the web process plus any configured watchers) and check logs after significant changes

Naming Conventions

  • Use snake_case for files, methods, and variables
  • Use CamelCase for classes and modules
  • Follow Rails naming conventions for models, controllers, views

Architecture & Performance

  • Utilize ActiveRecord for database operations with proper indexing
  • Use PostgreSQL in production, with proper indexes, connection pooling, and safe/reversible migrations
  • Implement eager loading to prevent N+1 query problems
  • Apply fragment caching and Russian Doll caching strategies
  • Use service objects for complex business logic
  • Follow MVC architecture strictly
  • Keep controllers RESTful and focused

Rails 8 Defaults

Rails 8 ships with a "no PaaS needed" stack — favor these built-ins over adding external services unless there's a specific reason not to:

  • Solid Queue — database-backed ActiveJob adapter; use it as the default background job backend instead of standing up Redis/Sidekiq unless job volume or feature needs (e.g., Sidekiq Pro batches) require it
  • Solid Cache — database-backed cache store; a reasonable default for Rails.cache without a separate Redis/Memcached deployment
  • Solid Cable — database-backed Action Cable adapter for WebSockets without Redis
  • Propshaft — the default asset pipeline; simpler than Sprockets, just serves fingerprinted files without a bundling step
  • Kamal — the default deployment tool for shipping containerized Rails apps to your own servers

Frontend & UI

  • Employ Hotwire (Turbo and Stimulus) for standard Rails interactivity and dynamic interactions without full page reloads
  • Reach for a Vite-managed JS pipeline (e.g., vite_rails) only when you actually need npm-managed JavaScript (React/Vue components, complex bundling) — don't add it by default
  • Design responsively with Tailwind CSS
  • Maintain DRY views through helpers and partials
  • Use ViewComponents for reusable UI components

Security

  • Implement authentication/authorization via Devise or Pundit
  • Use strong parameters in controllers to prevent mass assignment vulnerabilities
  • Sanitize user inputs appropriately
  • Use CSRF protection tokens
  • Implement proper session management

Testing

  • Write comprehensive Minitest or RSpec coverage for models, controllers, and integration flows, following TDD practices
  • Use FactoryBot for test data generation rather than fixtures
  • Mock external services; stub predefined return values
  • Use shared examples for common behaviors across different contexts
  • Ensure each test is independent; avoid shared state between tests

Best Practices

  • Keep controllers thin, models fat (but not too fat)
  • Use concerns for shared functionality
  • Implement background jobs with Sidekiq or ActiveJob
  • Use proper database migrations
  • Follow RESTful routing conventions

來源與署名

來源:mindrally/skills位於ruby-rails提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架