ookami-coding-style-rails
SKILL.md
Rails Coding Style
Follow these conventions when writing Ruby/Rails code. Full reference: https://github.com/ookamiinc/guides/blob/master/coding_style/rails.md
General Style
- Use American English.
- Use 2-space indentation, no tabs.
- No trailing whitespace. Blank lines should not have any spaces.
- Indent after
private/protected. - Prefer
{ a: :b }over{ :a => :b }(new-style hash syntax). - Prefer
&&/||overand/or. - Use
MyClass.my_method(my_arg)— notmy_method( my_arg )ormy_method my_arg. - Use
a = b— nota=b(spaces around operators). - Prefer
method { do_stuff }overmethod{do_stuff}for single-line blocks. - Follow the conventions already present in the source code.
Check Your Code
Run rubocop before submitting:
rubocop -RD
Configuration
- Put custom initialization code in
config/initializers. - Keep initialization code for each gem in a separate file named after the gem (e.g.,
carrierwave.rb,devise.rb). - Adjust settings for development, test, and production in
config/environments/. - Keep configuration applicable to all environments in
config/application.rb.
Controllers
- Keep controllers skinny — they should only retrieve data for the view layer and contain no business logic.
- Each controller action should ideally invoke only one method other than an initial
findornew.
Models
- Use meaningful but short names without abbreviations.
ActiveRecord Ordering
Avoid altering ActiveRecord defaults unless you have a very good reason. Group macro-style methods at the beginning of the class definition in this order:
default_scope- Constants
attr_accessor/attr_accessiblemacrosenum(prefer hash syntax)- Associations (
belongs_to,has_many, etc.) - Validations (
validates) - Callbacks (
before_save, etc.) - Other macros (devise, etc.)
Example:
class User < ActiveRecord::Base
default_scope { where(active: true) }
COLORS = %w(red green blue)
attr_accessor :formatted_date_of_birth
attr_accessible :login, :first_name, :last_name, :email, :password
enum gender: { female: 0, male: 1 }
belongs_to :country
has_many :authentications, dependent: :destroy
validates :email, presence: true
validates :username, presence: true
validates :username, uniqueness: { case_sensitive: false }
before_save :cook
before_save :update_username_lower
end
Weekly Installs
3
Repository
ookamiinc/guidesGitHub Stars
1
First Seen
13 days ago
Security Audits
Installed on
claude-code3
mcpjam2
kilo2
junie2
windsurf2
zencoder2