1
我在我的應用程序中使用cancancan和activeadmin寶石,在cancan gem自定義操作不起作用。cancancan自定義操作不起作用
ability.rb
if ((user.has_role? :HRMS_Supervisor) && (user.has_application? :HRMS))
can :manage, User
can :approve, User // custom action
end
if ((user.has_role? :HRMS_Employee) && (user.has_application? :HRMS))
can :read, Employee
can :manage, User
can :employee_access, User // custom action
end
我activeadmin文件
ActiveAdmin.register Teleworker do
scope :pending, default: true
scope :approved
scope :rejected, if: proc{ can? :employee_access, current_user }
scope :all
index do
selectable_column
column "Action" do |resource|
links = ''.html_safe
if can? :approve, current_user
links += link_to "approve", resource_path(resource), class: "member_link view_link"
end
end
end
被拒絕的範圍和的link_to 「批准」 顯示的是兩個角色。如何解決這個問題。
...並且您還需要授權您的自定義操作:https://github.com/CanCanCommunity/cancancan/wiki/Authorizing-controller-actions – nistvan 2014-12-04 09:08:15
非常感謝它的作品。 – 2014-12-04 09:10:44