Closed dorianmariecom closed 2 years ago
I also have that for inside my policies:
def can?(action, record)
policy(record).public_send("#{action}?")
end
def policy(record)
if record.is_a?(String) || record.is_a?(Symbol)
"#{record.to_s.camelize}Policy".constantize.new(user, record)
else
"#{record.class}Policy".constantize.new(user, record)
end
end
that's more hacky though
Thanks for the suggestion - this is neat, but it doesn't feel like something we'd want to include in the project.
I have this in my
application_helper.rb
which I find quite helpful, maybe others can benefit from it?It's kinda inspired by cancan(can) and allows to do things like: