rails-patterns
यह क्या करती है
यह guide सिखाती है कि Ruby on Rails applications में code को community के best practices के हिसाब से कैसे व्यवस्थित करें। यह आपके project को साफ़-सुथरा और आसानी से समझ में आने लायक रखने में मदद करती है, भले ही वह बड़ा होता जाए।
कब इस्तेमाल करें
- ✓नया Rails project शुरू करते समय।
- ✓जब आपके project की कोई फ़ाइल बहुत बड़ी हो जाए।
- ✓किसी और का code review करते समय।
Skill का लिंक
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/rails-patterns/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“नया invoice बनाने के लिए मैं code को कैसे व्यवस्थित करूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह बताती है कि हर तरह का code (जैसे controllers, services, models) किस folder में रखना है। जटिल काम के लिए यह सुझाती है कि सब कुछ controller में डालने के बजाय service या form objects का इस्तेमाल करें।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Rails Patterns
Framework patterns for modern Ruby on Rails applications (Rails 7.1+ and 8.x). Rails is opinionated by design; these are the patterns the community has converged on for apps that stay maintainable past the 50-model mark. This skill is the "how." For the "what" and "when" (the decisions about which pattern to reach for), see the Ruby patterns rules — rules/ruby/patterns.md in this repository, installed as rules/ecc/ruby/patterns.md.
When to Activate
- Building a Rails application (full-stack, API-only, or hybrid)
- Reviewing a PR that touches
app/orconfig/ - Generating models, controllers, services, or jobs
- A controller action grows past ~10 lines
- A model file grows past ~200 lines
- ActiveRecord queries start appearing in controllers or views
Core Concepts
The directory contract
Rails apps follow a predictable structure. Add directories deliberately, not casually.
app/
models/ ActiveRecord models. Persistence and domain logic close to the data.
controllers/ HTTP request handling. Thin orchestration only.
views/ ERB templates. No business logic.
components/ ViewComponent classes. View logic that needs tests.
services/ Service objects. Multi-step business operations.
forms/ Form objects. Complex form handling across multiple models.
queries/ Query objects. Reusable, composable ActiveRecord queries.
jobs/ Background jobs. Async work via Solid Queue, Sidekiq, or GoodJob.
mailers/ ActionMailer classes.
helpers/ View helpers. Tiny presentational logic only.
policies/ Authorization policies (if using Pundit). Optional.
channels/ ActionCable channels for WebSocket work.
Avoid app/lib/, app/utils/, app/managers/. If something does not fit the directories above, the design usually needs rethinking, not a new directory. Truly generic code goes in lib/.
Skinny controllers
Controllers receive a request, delegate to the right object, and render a response. Business logic lives elsewhere. (Per the Ruby patterns rules, extract to a service object when the controller starts carrying multiple responsibilities.)
Service objects
The default for business operations that touch more than a single model save. Conventions that keep them consistent:
- Namespace by domain (
Invoices::Create), not by suffix (InvoiceCreator). - A class method
.calldelegates to an instance#call. - Return a Result object, not a boolean or a bare record, so the caller can branch on success, errors, and the affected record.
- Wrap multi-record writes in a transaction.
- Keep each service single-purpose (
Invoices::Create,Invoices::MarkPaid), neverInvoices::Manager.
Form objects
When a form spans multiple models or has fields that do not map to columns, use a form object rather than nested attributes or virtual attributes on the wrong model. It quacks like a model to the view (form_with model: @form) while composing records cleanly.
Query objects
For ActiveRecord queries reused across controllers or services, or too complex for a scope, extract a query object that accepts a scope as input so it composes. Rule of thumb: a scope that grows past three chained conditions or starts taking parameters wants to be a query object.
Background jobs
Offload anything slow. (Per the Ruby patterns rules, Solid Queue for greenfield Rails 8 with modest throughput; Sidekiq when you need mature observability, high throughput, or existing Redis.) Regardless of adapter: pass IDs not records, make perform idempotent, and set retry_on/discard_on explicitly.
ViewComponent over partials
For view logic with conditional rendering, more than two arguments, or reuse across more than three places, prefer a ViewComponent. Components are testable in isolation and surface their interface explicitly; partials with deep conditional logic become debt.
Hotwire: Turbo and Stimulus
The default Rails frontend stack. (Per the Ruby patterns rules, prefer Hotwire for server-rendered apps; reach for React/Vue only when interaction complexity justifies the client surface.) Turbo Frames for partial page updates, Turbo Streams for server-driven updates, Stimulus for small client-side behaviors next to the markup.
The Rails 8 Solid stack
…
अक्सर पूछे जाने वाले सवाल
'skinny controllers' क्या होते हैं?
इसका मतलब है कि controllers (जो web requests संभालते हैं) छोटे होने चाहिए और केवल काम का समन्वय करें। जटिल logic को code के दूसरे हिस्सों, जैसे service objects, को सौंप देना चाहिए।
'service objects' क्या हैं?
ये code के ऐसे टुकड़े हैं जो एक खास और स्पष्ट काम करते हैं, जैसे invoice बनाना। इनसे controllers साफ़ रहते हैं और code ज़्यादा व्यवस्थित रहता है।
'partials' की जगह 'ViewComponent' क्यों इस्तेमाल करें?
ViewComponents की testing आसान होती है और जटिल view logic को व्यवस्थित रखना सरल होता है। इसलिए code पारंपरिक 'partials' से ज़्यादा मज़बूत और आसानी से संभालने लायक बनता है।
जानकारी
लेखक का मूल विवरण
Ruby on Rails framework patterns for Rails 7.1+ and 8.x apps. Covers the directory contract, skinny controllers with service objects, form objects, query objects, idiomatic ActiveRecord, background jobs, ViewComponent, Hotwire, and the Rails 8 Solid stack. Use when building or reviewing Rails apps, controllers, models, services, jobs, or views.
repo: affaan-m/ECC
लोकप्रियता
- GitHub स्टार
- 280k
- रैंकिंग में स्थान
- #235
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
accessibility
280kयह आपके एजेंट को ऐसे इंटरफ़ेस बनाने में मदद करता है जिन्हें हर कोई इस्तेमाल कर सके। यह पक्का करता है कि वेबसाइट और ऐप दिव्यांग लोगों के लिए भी अच्छे से काम करें, जैसे नेत्रहीन या जिन्हें चलने-फिरने में दिक्कत होती है।
agent-architecture-audit
280kयह आपके एजेंट को जाँचने देता है कि सब कुछ सही से चल रहा है। यह AI सिस्टम में समस्याएँ ढूँढकर ठीक करता है, ताकि वे उम्मीद के मुताबिक काम करें।
agent-eval
280kयह आपके एजेंट को अलग-अलग AI coding tools की तुलना करने में मदद करता है। यह मापता है कि किसी खास काम के लिए कौन सा टूल ज़्यादा तेज़, सस्ता और भरोसेमंद है।
agent-harness-construction
280kयह आपके एजेंट को काम कैसे करना है, यह बेहतर समझने में मदद करता है। यह उन tools और instructions को बेहतर बनाता है जिनका एजेंट इस्तेमाल करता है, ताकि उसकी सफलता की संभावना बढ़े।
मिलती-जुलती skills
shopify
260kआपके एजेंट को Shopify GraphQL API से स्टोर का डेटा पढ़ने और अपडेट करने देती है, जैसे उत्पाद, स्टॉक, ऑर्डर और ग्राहक।
rest-graphql-debug
260kआपके एजेंट को REST या GraphQL API कॉल क्यों विफल होती है, यह पता करने में मदद करती है, कनेक्शन, लॉगिन, अनुरोध फ़ॉर्मैट और जवाब को एक-एक परत करके जाँचते हुए।
har-derived-api-client
260kआपके एजेंट को किसी वेबसाइट के नेटवर्क ट्रैफ़िक को एक बार रिकॉर्ड करके सीधा API क्लाइंट बनाने देती है, ताकि हर बार पेज पर क्लिक करना न पड़े।