ruby on rails - How to show specific parameters based on auth using pundit? -
say have user
model has username
, full_name
. want render user object using active model serializer
, render specific parameters based on if current_user
nil or logged in. since i'm using pundit
well, wondering if there way using pundit
.
e.g.
user nil
{id:1, username: 'foo'}
user logged in
{id:1, username: 'foo', full_name: 'bar'}
why not check if current_user
nil
in user
serializer. not sure version on can 0.9 version
class userserializer < activemodel::serializer attributes :id, :username, :full_name def filter(keys) if scope.blank? #current_user not logged in keys - [:full_name] else keys end end end
Comments
Post a Comment