Skip to content

Instantly share code, notes, and snippets.

@panSarin
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save panSarin/2a8ef53af402bbdc4d29 to your computer and use it in GitHub Desktop.

Select an option

Save panSarin/2a8ef53af402bbdc4d29 to your computer and use it in GitHub Desktop.
controller default scopes
class ClientsController < CompanyScopedController
before_filter :set_client, only: [:show, :edit, :update, :destroy]
def index
@clients = clients_scoped.paginate(per_page: 20, page: params[:page])
end
private
def set_client
@client = clients_scoped.find(params[:id])
end
end
class CompanyScopedController < ApplicationController
def addresses_scoped
Address.for_company(current_user)
end
def clients_scoped
Client.for_company(current_user)
end
#... and so on for every model that we use at least once in our controllers
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment