-
-
Save zdennis/21365 to your computer and use it in GitHub Desktop.
This file contains 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 User < ActiveRecord::Base | |
has_many :roles | |
# can answer... has_role?, as(...), etc | |
include Roles::RoleMethods | |
end | |
class ApplicationController | |
rescue_from Roles::RoleNotFound, AccessDenied do | |
# send to 401.html, send back some error text/json, whatever... | |
end | |
end | |
class InvoicesController < ApplicationController | |
before_filter :login_required | |
def show | |
@invoice = current_user.as('fiscal staff').invoices.find params[:id] | |
end | |
def create | |
@invoice = current_user.as('fiscal admin').create_invoice params[:invoice] | |
end | |
def index | |
@invoices = current_user.as('fiscal staff').invoices.all | |
end | |
def update | |
@invoice = current_user.as('fiscal admin').invoices.find params[:id] | |
end | |
end | |
class FiscalAdmin < Roles::Base | |
alias :user, :source | |
def invoices | |
Invoice.owned_by(user) | |
end | |
def create_invoice attrs | |
Invoice.create! attrs | |
end | |
end |
This file contains 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment