GET CurrentUser abilities to Angular client from Rails/Ruby server

80 views
Skip to first unread message

dan.s....@gmail.com

unread,
Aug 13, 2014, 6:07:45 PM8/13/14
to canc...@googlegroups.com
I found out that I get the abilities on object like this:

class UserSerializer < ActiveModel::Serializer
attributes :id, :email, :can_update, :can_delete

def can_update
scope.can?(:update, object)
end

def can_delete
scope.can?(:destroy, object)
end
end


BUT I really want to all abilities (:read and :create) for CurrentUser when s/he sign in to hide whatever the user hasn't permission to.

How do I get CurrentUser abilities as a hash?

brite

unread,
Nov 25, 2014, 12:32:27 PM11/25/14
to canc...@googlegroups.com, dan.s....@gmail.com
Cancancan defines `current_ability` as the abilities of your `current_user`.  Alternatively, you could also do: Ability.new(user_instance)... there is a hash in there of the user's role you can parse and use however you like.
Reply all
Reply to author
Forward
0 new messages