Last active
August 29, 2015 14:04
-
-
Save panSarin/2a8ef53af402bbdc4d29 to your computer and use it in GitHub Desktop.
controller default scopes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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