Skip to content

Instantly share code, notes, and snippets.

@FaisalAl-Tameemi
Created March 31, 2016 16:39
Show Gist options
  • Save FaisalAl-Tameemi/481709b856eee85912439902824d63a0 to your computer and use it in GitHub Desktop.
Save FaisalAl-Tameemi/481709b856eee85912439902824d63a0 to your computer and use it in GitHub Desktop.

Topics covered

  • Review of Rails Scopes & Namespacing

     namespace :admin do
         resources :reviews, only: [:index]
     end

    which is synonomous with...

    scope '/admin', as: 'admin' do
        resources :reviews, only: [:index]
    end
  • Refresher on query modifiers * offset and limit * order * distinct * group * group(...).having(...)

  • Scopes * named scopes with lambda blocks * Lambda blocks are anonymous methods * scope chaining * default scope * unscope / unscoped / reorder -> Remove parts of a scope when needed

  • Shortcuts

    • Model.find_or_create_by
    • Model.find_or_initialize_by (= Model.find + Model.new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment