Skip to content

Whiteboard Style Guide: Rails

Chad edited this page Jun 29, 2015 · 9 revisions

Whiteboard-Rails-Style-Guide

Standard rules (suggestions) for Rails code at Whiteboard

Models

Model File Structure
class User < ActiveRecord::Base
  
  # scopes
  
  # CONSTANTS
  
  # attr_ - whatevers
  
  # belongs_tos
  
  # has_manys
  
  # validations on fields
  
  # custom validations
  
  # callbacks
  
  # methods
  
end
  

Controllers

Controller File Structure
class PostsController < ApplicationController

  # includes Modules / Concerns
  
  # before / after filters

  # REST actions ... index, show, create etc

  # Non REST actions ... any custom controller methods / actions

private

  # params, small methods to help application flow. KEEP CONTROLLER ACTIONS SMALL

  # helper methods for views. Define helper method directly under method declaration
  # That way you know immediately whether a method is defined as a helper method

  def post_owner
    post.user
  end
  helper_method :post_owner


end

Clone this wiki locally