I wish to allow admins to create posts with custom fields, but still wish for them to use the same create action as normal users use.
I thought to do this:
class Ability
include CanCan::Ability
def initialize(user)
if user.admin?
can :specialize, Post
end
end
end
Then in my controller:
def create
@post = Post.new
if can? :specialize, @post
do_fancy_things_here
end
end
The weird thing is, do_fancy_things_here is ALWAYS running regardless of if the user is an admin or not.
This is strange. The only way I deviated from the cancan manuals is that :specialize does not actually map to a controller action. Does that matter?
Your have to use
authorize! :specialize, @postin your controller.https://github.com/ryanb/cancan/wiki/Authorizing-Controller-Actions