gregbell/active_admin — Issue #762: changing the form?
Author: cgunnels
Created: 2011-11-18 23:22:12+00:00
State: open

I am trying to use the can? method from CanCan gem but my approved field isn't working, I get undefined method `can?' for #

form do |f|
f.inputs do
f.input :approved if can?(:approve, Domain)
end
f.buttons
end

So I tried calling can? on my current user like:
f.inputs do
f.input :approved if Thread.current[:user].can?(:approve, Domain)
end

I get an undefined method can? for user.

I should mention that I have CanCan installed and I am running controller.authorize_resource earlier in my aa controller.

My ability class:
class Ability
include CanCan::Ability

def initialize(user)
# Define abilities for the passed in user here.
unless user.nil? || user.role.nil?
if user.is?(:admin)
can :manage, :all
else
user.role.cached_permissions.each do |permission|
perm = permission.split("#")
begin
can perm[1].to_sym, perm[0].classify.constantize
rescue NameError
raise ActiveRecord::RecordNotFound
end
end
end
else
cannot :manage, :all
end
end

end