원클릭으로
model-creation
Create and modify Rails models following project conventions for STI, enums, validations, counter caches, and scopes
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Create and modify Rails models following project conventions for STI, enums, validations, counter caches, and scopes
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Create and manage Solid Queue background jobs with perform_now vs perform_later patterns
Perform deep critical analysis of changes with focus on performance vs sustainability trade-offs
Add controllers and routes following project patterns for organizer namespaces, strong params, and Turbo
Build Rails forms with Tailwind CSS, Turbo integration, and strong params validation
Write database migrations for PostgreSQL with PostGIS, UUID primary keys, enums, and counter caches
Create service objects in app/services/ using module namespaces for encapsulation
| name | model-creation |
| description | Create and modify Rails models following project conventions for STI, enums, validations, counter caches, and scopes |
| license | MIT |
bin/rails g model{ presence: true })app/models/<name>.rbapp/models/concerns/# frozen_string_literal: true
class ModelName < ApplicationRecord
# Associations
belongs_to :parent, optional: true
has_many :children, dependent: :destroy
# Enums
enum :status, { draft: 0, active: 1 }, default: :draft
# Validations (Rails 8 style)
validates :field, { presence: true }
validates :other, { uniqueness: { scope: :parent_id } }
# Scopes
scope :active, -> { where(status: :active) }
# Callbacks (if needed)
before_save :compute_slug
end
Event < ApplicationRecord (type column: type)Tournament < Event (no explicit type needed if base defaults)t.string "type", default: "Tournament", null: falseapp/models/tournament.rb, app/models/league.rbtype: "Tournament" fieldenum :state, { draft: 0, open: 1 }, default: :draftenum :play_mode, { scheduled: 0, pickup: 1 }, prefix: true
play_mode_scheduled?, play_mode_pickup?, play_mode_scheduled!alias pickup_play_mode? play_mode_pickup?state: 3belongs_to :event, counter_cache: truet.integer "event_participants_count", default: 0, null: falseEvent.reset_counters in test_helper.rb setup blockvalidates :name, { presence: true } — preferred over validates :name, presence: truevalidates :field, { uniqueness: { scope: :parent_id } }validates :other, { numericality: { greater_than: 0 }, allow_blank: true }validate :must_match_kind_with_categorywith_options presence: true do ... end for grouped presencebelongs_to with optional: true when foreign key is nullablehas_many ... dependent: :destroy for ownershiphas_many ... dependent: :nullify for soft referenceshas_one ... dependent: :nullify for one-to-onethrough associations: has_many :players, through: :event_participantshas_many :results, -> { publishable }scope :ongoing, -> { where(state: %i[swiss single_elimination]) }scope :ranked, -> { order(points: :desc) }scope :for_organizer, ->(organizer) { where(event_organizer: organizer) }joins(:parent).where.not(parents: { finished_at: nil })before_validation over before_save when value computation is neededafter_update :action, if: -> { field_previously_changed? } for change-triggered actionsbefore_save :reset_cache, if: -> { linked_previously_changed? }previously_changed? instead of was for Rails 8 compatibilityattribute :field, :type for typed attributes with defaultsnormalizes :field, with: ->(e) { e.strip.downcase } for normalizationfind_or_initialize_by for upsert patternsfind_or_create_by for create-or-retrieve patternsupdate_columns for bypassing callbacks (use sparingly)app/models/user.rb — Example: STI-like setup, callbacks, normalizationapp/models/event.rb — Example: counter caches, STI base, scopesapp/models/infraction.rb — Example: enum hierarchy, custom validationsapp/models/league.rb — Example: prefixed enums, aliased predicates