Skip to content

Instantly share code, notes, and snippets.

@panSarin
Created November 19, 2012 15:27
Show Gist options
  • Save panSarin/4111261 to your computer and use it in GitHub Desktop.
Save panSarin/4111261 to your computer and use it in GitHub Desktop.
cancan issue
class Ability
include CanCan::Ability
def initialize(user)
if user.role?('admin')
can :manage, :all
end
if user.role?('user_manager')
can :manage, User
end
if user.role?('agent')
can :create, Policy
can :update, Policy, :policies_users => {user_id: user.id, contract: Contract.find_by_name("Agent") }
can :manage, Calculation, user_id: user.id
end
end
#and in my view:
- Policy.joins(:policies_users).where("policies_users.user_id != #{current_user.id} and contract_id = #{Contract.find_by_name('Agent').id}").each do |p|
= can? :update, p
%br
= can? :update, Policy, Policy.joins(:policies_users).where("policies_users.user_id != #{current_user.id} and contract_id = #{Contract.find_by_name('Agent').id}").all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment