搜索

PythonReactSEOPDF
GitHub Skill

rails-style-guide

Rails code style conventions. Use when working with Rails projects, running commands, or writing Rails code.

manuelmeurer☆ 0 仓库 Stars1 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Rails Style Guide

Apply these conventions when working with Rails projects.

Guidelines

  • In HAML, put Ruby expressions on their own line; avoid inline =.

Binstubs

When running Rails executables, always check for binstubs first:

  1. Check for binstub: Look for bin/rails, bin/rspec, bin/rubocop, etc.
  2. Use binstub if exists: Run bin/rails instead of bundle exec rails
  3. Fallback to bundle exec: Only use bundle exec if no binstub exists
# Good - check for binstub first
bin/rails db:migrate
bin/rspec spec/models/user_spec.rb

# Only if binstubs don't exist
bundle exec rails db:migrate
bundle exec rspec spec/models/user_spec.rb

When bundle exec fails: Inform the user that a binstub might resolve the issue, as binstubs can have different load paths or configurations.

Namespaces

Treat each Rails app as divided into namespaces. Common ones are web (the marketing website), admin (the admin area), and users (the login area for users).

For each namespace:

  • Routes live in config/routes/NAMESPACE.rb
  • Views live in app/views/NAMESPACE
  • Controllers live in app/controllers/NAMESPACE
  • Styles live in app/assets/stylesheets/NAMESPACE.scss
  • JavaScript lives in app/javascripts/NAMESPACE.js
  • I18n locale files live in config/locales/NAMESPACE.LOCALE.yml

Never create a new namespace unless the user explicitly prompts it. If you are unsure which namespace a change belongs to, ask the user.

Setting datetime/date columns to current time

When setting a datetime or date column to the current time/date, check if the model includes HasTimestamps[column]. If so, use the bang method instead of direct assignment:

# Bad - direct assignment when HasTimestamps is available
message.update!(sent_at: Time.current)

# Good - use the bang method from HasTimestamps
message.sent!

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!