I am trying to make an app with Rails 4.
I have defined a series of roles with Rolify gem.
Now, I want to use pundit to allow users with a role to do certain things. Where more than one type of role can do a thing, I have defined a group of roles.
In my application_policy, I have defined private methods which set out the groups of roles that I want to use in the pundit permissions.
My application policy instantiates user and record. I then define record as the name of the relevant model (the same name as the policy for that model).
I have:
class ApplicationPolicy
attr_reader :user, :record
def initialize(user, record)
@user = user
@record = record
end
def index?
false
end
def show?
scope.where(:id => record.id).exists?
end
def create?
false
end
def new?
create?
end
def update?
false
end
def edit?
update?
end
def destroy?
false
end
def scope
Pundit.policy_scope!(user, record.class)
end
class Scope
attr_reader :user, :scope
def initialize(user, scope)
@user = user
@scope = scope
end
def resolve
scope
end
end
private
def cf_legal
[ :Admin, :CF_Legal, :CF_Policy_Manager ]
end
def cf_content
[ :Admin, :CF_Author, :CF_Editor ]
end
end
Then in my content policy, I want to say:
def record
content
end
def create
user.has_role? :cf_content
end
When I save this and try it, I can't see the thing that I am supposed to see (as a user with the role Author.
Can anyone see how to do this?