Install
$ agentstack add skill-shoebtamboli-rails-claude-skills-rails-models ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
Rails Models (ActiveRecord)
Quick Reference
| Pattern | Example | |---------|---------| | Model Generation | rails g model User name:string email:string | | Migration | rails g migration AddAgeToUsers age:integer | | Validation | validates :email, presence: true, uniqueness: true | | Association | has_many :posts, dependent: :destroy | | Callback | before_save :normalize_email | | Scope | scope :active, -> { where(active: true) } | | Query | User.where(active: true).order(created_at: :desc) |
Model Definition
class User { where(active: true) }
scope :recent, -> { order(created_at: :desc) }
# Class methods
def self.search(query)
where("name ILIKE ?", "%#{query}%")
end
# Instance methods
def full_name
"#{first_name} #{last_name}"
end
private
def normalize_email
self.email = email.downcase.strip
end
end
Migrations
Creating Tables
class CreateUsers { where(published: true) }, class_name: 'Book'
end
class Book { where(published: true) }
scope :recent, -> { order(created_at: :desc) }
scope :by_author, ->(author_id) { where(author_id: author_id) }
scope :created_between, ->(start_date, end_date) {
where(created_at: start_date..end_date)
}
# Chaining scopes
# Post.published.recent.limit(10)
end
# Query methods
Post.where(published: true)
Post.where("views > ?", 100)
Post.where(author_id: [1, 2, 3])
Post.where.not(category: 'draft')
# Ordering
Post.order(created_at: :desc)
Post.order(views: :desc, created_at: :asc)
# Limiting
Post.limit(10)
Post.offset(20).limit(10)
# Joins
Post.joins(:author)
Post.joins(:author, :comments)
Post.left_joins(:comments)
# Includes (eager loading)
Post.includes(:author, :comments)
Post.includes(author: :profile)
# Selecting specific fields
Post.select(:id, :title, :created_at)
Post.pluck(:title)
Post.pluck(:id, :title)
# Aggregations
Post.count
Post.average(:views)
Post.maximum(:views)
Post.minimum(:views)
Post.sum(:views)
# Group
Post.group(:category).count
Post.group(:author_id).average(:views)
Enums
class Post < ApplicationRecord
enum status: {
draft: 0,
published: 1,
archived: 2
}
# Or with prefix/suffix
enum visibility: {
public: 0,
private: 1
}, _prefix: :visibility
# Usage:
# post.draft!
# post.published?
# Post.published
# post.visibility_public!
end
Model Concerns
# app/models/concerns/taggable.rb
module Taggable
extend ActiveSupport::Concern
included do
has_many :taggings, as: :taggable
has_many :tags, through: :taggings
end
class_methods do
def tagged_with(tag_name)
joins(:tags).where(tags: { name: tag_name })
end
end
def tag_list
tags.pluck(:name).join(', ')
end
end
# Usage in model
class Post < ApplicationRecord
include Taggable
end
Best Practices
- Fat models, skinny controllers - Business logic belongs in models
- Use scopes for common queries
- Validate at database level with constraints when possible
- Use indexes for frequently queried columns
- Eager load associations to avoid N+1 queries
- Use concerns to share behavior across models
- Keep callbacks simple - avoid complex logic
- Use transactions for multi-step operations
- Avoid callbacks for cross-cutting concerns - use service objects instead
Common Pitfalls
- N+1 queries: Use
includes,preload, oreager_load - Callback hell: Keep callbacks simple, use service objects for complex logic
- Mass assignment vulnerabilities: Use strong parameters in controllers
- Missing indexes: Add indexes for foreign keys and frequently queried columns
- Ignoring database constraints: Add NOT NULL, unique constraints in migrations
References
- Rails Guides - Active Record
- Rails Guides - Validations
- Rails Guides - Associations
- Rails Guides - Migrations
- Rails Guides - Queries
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: Shoebtamboli
- Source: Shoebtamboli/railsclaude_skills
- License: MIT
- Homepage: https://rubygems.org/gems/railsclaudeskills
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.