Last active
August 29, 2015 14:13
-
-
Save tsechingho/714d6f50865f86d6ac55 to your computer and use it in GitHub Desktop.
Revisions
-
tsechingho revised this gist
Jan 12, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # app/controllers/application_controller.rb or any controller class ApplicationController < ActionController::Base def current_ability @current_ability ||= Ability.ability_for current_customer -
tsechingho revised this gist
Jan 12, 2015 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # app/controllers/application_controller.rb class ApplicationController < ActionController::Base def current_ability @current_ability ||= Ability.ability_for current_customer end end
-
tsechingho created this gist
Jan 12, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ # app/models/ability.rb module Ability class << self def ability_for user, options = {} abilities = AnonymousAbility.new return abilities unless user abilities.merge MemberAbility.new user, options if user.has_role? 'administrator' abilities.merge AdministratorAbility.new end abilities end 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ # app/abilities/member_ability.rb class MemberAbility include CanCan::Ability attr_accessor :current_user def initialize current_user, options = {} can :update, User do |user| user.email == current_user.email end can :update, Profile do |profile| profile.owners.include? current_user end end end