重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
moai-lang-ruby by modu-ai/moai-adk
npx skills add https://github.com/modu-ai/moai-adk --skill moai-lang-rubyRuby 3.3+ 开发专家 - 精通 Rails 7.2、ActiveRecord、Hotwire/Turbo、RSpec 以及现代 Ruby 模式。
自动触发:包含 .rb 扩展名的文件、Gemfile、Rakefile、config.ru、Rails 或 Ruby 相关讨论
核心能力:
Rails 控制器模式:
创建继承自 ApplicationController 的 UsersController。添加 before_action 用于 set_user,仅在 show、edit、update 和 destroy 动作中调用。定义 index 方法,将 User.all 赋值给实例变量。定义 create 方法,使用 user_params 创建新 User。使用 respond_to 块,其中 format.html 在成功时重定向或在失败时渲染 new 并返回 unprocessable_entity 状态,format.turbo_stream 用于 Turbo 响应。添加私有方法 set_user,通过 params id 查找用户。添加 user_params 方法,要求 user 参数并允许 name 和 email。
ActiveRecord 模型模式:
创建继承自 ApplicationRecord 的 User 模型。定义 has_many :posts 并设置 dependent: :destroy,定义 has_one :profile 并设置 dependent: :destroy。添加对 email 的验证,要求存在性、唯一性,并使用 URI::MailTo::EMAIL_REGEXP 验证格式。添加对 name 的验证,要求存在性且长度在 2 到 100 之间。定义 active 作用域,筛选 active 为 true 的记录。定义 recent 作用域,按 created_at 降序排序。创建 full_name 方法,返回 first_name 和 last_name 用空格连接并去除首尾空格的结果。
RSpec 测试模式:
为 User 模型类型创建 RSpec.describe。在 describe validations 块中,添加对 email 的 validate_presence_of 和 validate_uniqueness_of 的期望。在 describe full_name 块中,使用 let 构建一个 first_name 为 John、last_name 为 Doe 的用户。添加 it 块,期望 user.full_name 等于 "John Doe"。
YJIT 生产就绪:
YJIT 在 Ruby 3.3 中默认启用,可为 Rails 应用程序带来 15% 到 20% 的性能提升。通过使用 yjit 标志运行 ruby 或将 RUBY_YJIT_ENABLE 环境变量设置为 1 来启用。通过调用 RubyVM::YJIT.enabled? 方法检查状态。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用 case/in 进行模式匹配:
创建接受 response 参数的 process_response 方法。使用 case 配合 response 和 in 进行模式匹配。匹配 status: :ok 并提取 data 变量,输出成功消息。匹配 status: :error 并提取 msg 变量。匹配 status 并带有检查是否为 pending 或 processing 的守卫条件。使用 else 处理未知响应。
用于不可变结构体的 Data 类:
使用 Data.define 和 :name、:email 符号创建 User。添加块定义 greeting 方法,返回包含 name 的问候消息。使用关键字参数创建 user 实例。访问 name 属性并调用 greeting 方法。
无结束方法定义:
创建 Calculator 类,使用等号语法为单表达式方法定义 add、multiply 和 positive? 方法。
Gemfile 中的应用程序设置:
将 source 设置为 rubygems.org。添加 rails 版本约束为 7.2,pg 为 1.5,puma 为 6.0 或更高,turbo-rails,stimulus-rails,以及 sidekiq 为 7.0。在 development 和 test 组中添加 rspec-rails 为 7.0,factory_bot_rails,faker,以及 rubocop-rails 并设置 require: false。在 test 组中添加 capybara 和 shoulda-matchers。
包含 Concerns 的模型:
创建扩展自 ActiveSupport::Concern 的 Sluggable 模块。在 included 块中添加 before_validation 用于在创建时 generate_slug,以及验证 slug 的存在性和唯一性。定义 to_param 返回 slug。添加私有方法 generate_slug,如果 title 存在且 slug 为空,则从参数化的 title 设置 slug。创建 Post 模型,包含 Sluggable,定义 belongs_to :user,has_many :comments 并设置 dependent: :destroy,has_many_attached :images。添加验证和 published 作用域。
服务对象模式:
创建 UserRegistrationService,其 initialize 方法接受 user_params。定义 call 方法创建 User,使用 ActiveRecord::Base.transaction 来保存用户、创建个人资料和发送欢迎邮件。返回包含 success: true 和 user 的 Result。救援 RecordInvalid 异常,返回包含 success: false 和 errors 的 Result。添加私有方法 create_profile 和 send_welcome_email。将 Result 定义为 Data.define,包含 :success, :user, :errors,并添加 success? 和 failure? 谓词方法。
Turbo Frames 模式:
在 index 视图中,使用 turbo_frame_tag 并指定 id 为 posts,迭代 posts 并渲染每个。在 post 局部视图中,使用 turbo_frame_tag 并指定 dom_id(post),其中包含带有 h2 链接和截断内容段落的 article。
Turbo Streams 模式:
在控制器的 create 动作中,从 current_user.posts 构建 post。使用 respond_to,其中 format.turbo_stream 和 format.html 根据保存成功与否进行重定向或渲染。在 create.turbo_stream.erb 视图中,使用 turbo_stream.prepend 将 post 添加到 posts,并使用 turbo_stream.update 更新 new_post 表单局部视图。
Stimulus 控制器模式:
在 JavaScript 控制器文件中,从 hotwired/stimulus 导入 Controller。导出默认类,该类继承自 Controller,并定义静态 targets 数组包含 input 和 submit。定义 connect 方法调用 validate。定义 validate 方法检查所有 input 目标是否有值,并相应地设置 submit 目标的禁用状态。
Factory Bot 模式:
在 factories 文件中,为 user 定义工厂,使用序列生成 email,使用 Faker::Name.name 生成 name,使用 "password123" 作为 password。添加 admin 特征,将 role 设置为 :admin 符号。添加 with_posts 特征,包含一个默认值为 3 的临时变量 posts_count,在 after(:create) 回调中使用 create_list 为用户创建帖子。
涵盖全面内容,包括:
请参阅:
常见问题:
Ruby 版本检查:
运行 ruby 并带上版本标志,确保是 3.3 或更高版本。通过运行 ruby -e 并加上 puts RubyVM::YJIT.enabled? 命令来检查 YJIT 状态。
Rails 版本检查:
运行 rails 并带上版本标志,确保是 7.2 或更高版本。运行 bundle exec rails about 获取完整的环境信息。
数据库连接问题:
资源管道问题:
运行 rails assets:precompile 编译资源。运行 rails assets:clobber 清除已编译的资源。
RSpec 设置问题:
运行 rails generate rspec:install 进行初始设置。运行 bundle exec rspec 并指定文件路径以运行单个规范。运行 bundle exec rspec 并带上 format documentation 标志以获得详细输出。
Turbo 和 Stimulus 问题:
运行 rails javascript:install:esbuild 进行 JavaScript 设置。运行 rails turbo:install 安装 Turbo。
最后更新:2026-01-11 状态:活跃 (v1.1.0)
每周安装次数
55
代码仓库
GitHub 星标数
907
首次出现
2026 年 1 月 22 日
安全审计
安装于
gemini-cli49
codex49
opencode48
cursor46
claude-code45
github-copilot44
Ruby 3.3+ Development Specialist - Rails 7.2, ActiveRecord, Hotwire/Turbo, RSpec, and modern Ruby patterns.
Auto-Triggers: Files with .rb extension, Gemfile, Rakefile, config.ru, Rails or Ruby discussions
Core Capabilities:
Rails Controller Pattern:
Create UsersController inheriting from ApplicationController. Add before_action for set_user calling only on show, edit, update, and destroy actions. Define index method assigning User.all to instance variable. Define create method creating new User with user_params. Use respond_to block with format.html redirecting on success or rendering new with unprocessable_entity status, and format.turbo_stream for Turbo responses. Add private set_user method finding by params id. Add user_params method requiring user and permitting name and email.
ActiveRecord Model Pattern:
Create User model inheriting from ApplicationRecord. Define has_many for posts with dependent destroy and has_one for profile with dependent destroy. Add validates for email with presence, uniqueness, and format using URI::MailTo::EMAIL_REGEXP. Add validates for name with presence and length minimum 2 maximum 100. Define active scope filtering where active is true. Define recent scope ordering by created_at descending. Create full_name method returning first_name and last_name joined with space and stripped.
RSpec Test Pattern:
Create RSpec.describe for User model type. In describe validations block, add expectations for validate_presence_of and validate_uniqueness_of for email. In describe full_name block, use let to build user with first_name John and last_name Doe. Add it block expecting user.full_name to eq John Doe.
YJIT Production-Ready:
YJIT is enabled by default in Ruby 3.3 providing 15 to 20 percent performance improvement for Rails applications. Enable by running ruby with yjit flag or setting RUBY_YJIT_ENABLE environment variable to 1. Check status by calling RubyVM::YJIT.enabled? method.
Pattern Matching with case/in:
Create process_response method taking response parameter. Use case with response and in for pattern matching. Match status ok with data extracting data variable and puts success message. Match status error with message extracting msg variable. Match status with guard condition checking pending or processing. Use else for unknown response.
Data Class for Immutable Structs:
Create User using Data.define with name and email symbols. Add block defining greeting method returning hello message with name. Create user instance with keyword arguments. Access name property and call greeting method.
Endless Method Definition:
Create Calculator class with add, multiply, and positive? methods using equals sign syntax for single expression methods.
Application Setup in Gemfile:
Set source to rubygems.org. Add rails version constraint for 7.2, pg for 1.5, puma for 6.0 or later, turbo-rails, stimulus-rails, and sidekiq for 7.0. In development and test group add rspec-rails for 7.0, factory_bot_rails, faker, and rubocop-rails with require false. In test group add capybara and shoulda-matchers.
Model with Concerns:
Create Sluggable module extending ActiveSupport::Concern. In included block add before_validation for generate_slug on create and validates for slug with presence and uniqueness. Define to_param returning slug. Add private generate_slug method setting slug from parameterized title if title present and slug blank. Create Post model including Sluggable with belongs_to user, has_many comments with dependent destroy, has_many_attached images. Add validations and published scope.
Service Objects Pattern:
Create UserRegistrationService with initialize accepting user_params. Define call method creating User, using ActiveRecord::Base.transaction to save user, create profile, and send welcome email. Return Result with success true and user. Rescue RecordInvalid returning Result with success false and errors. Add private methods for create_profile and send_welcome_email. Define Result as Data.define with success, user, and errors, adding success? and failure? predicate methods.
Turbo Frames Pattern:
In index view, use turbo_frame_tag with posts id and iterate posts rendering each. In post partial, use turbo_frame_tag with dom_id for post, containing article with h2 link and truncated content paragraph.
Turbo Streams Pattern:
In controller create action, build post from current_user.posts. Use respond_to with format.turbo_stream and format.html for redirect or render based on save success. In create.turbo_stream.erb view, use turbo_stream.prepend for posts with post, and turbo_stream.update for new_post form partial.
Stimulus Controller Pattern:
In JavaScript controller file, import Controller from hotwired/stimulus. Export default class extending Controller with static targets array for input and submit. Define connect method calling validate. Define validate method checking all input targets have values and setting submit target disabled accordingly.
Factory Bot Patterns:
In factories file, define factory for user with sequence for email, Faker::Name.name for name, and password123 for password. Add admin trait setting role to admin symbol. Add with_posts trait with transient posts_count defaulting to 3, using after create callback to create_list posts for user.
For comprehensive coverage including:
See:
Common Issues:
Ruby Version Check:
Run ruby with version flag for 3.3 or later. Check YJIT status by running ruby -e with puts RubyVM::YJIT.enabled? command.
Rails Version Check:
Run rails with version flag for 7.2 or later. Run bundle exec rails about for full environment information.
Database Connection Issues:
Asset Pipeline Issues:
Run rails assets:precompile to compile assets. Run rails assets:clobber to clear compiled assets.
RSpec Setup Issues:
Run rails generate rspec:install for initial setup. Run bundle exec rspec with specific file path for single spec. Run bundle exec rspec with format documentation for verbose output.
Turbo and Stimulus Issues:
Run rails javascript:install:esbuild for JavaScript setup. Run rails turbo:install for Turbo installation.
Last Updated: 2026-01-11 Status: Active (v1.1.0)
Weekly Installs
55
Repository
GitHub Stars
907
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
gemini-cli49
codex49
opencode48
cursor46
claude-code45
github-copilot44
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
125,600 周安装