Created
August 2, 2012 14:20
-
-
Save scho/3237417 to your computer and use it in GitHub Desktop.
Initializer for cancan within Netzke in order to use cancan helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initializer for cancan | |
# | |
# Extend Netzke::Base class in order to be able to include cancan helpers | |
class Netzke::Base | |
# cancan calls helper_method, which is present in any controller, but not in a netzke components | |
def self.helper_method(*args) | |
# Do nothing since we don't have a view layer in netzke components | |
end | |
# This method is overwritten in respect to current_user in netzke components | |
def current_ability | |
@current_ability ||= Ability.new(Netzke::Core.current_user) | |
end | |
end | |
# Add cancan helper methods to Netzke Components, e.g. can?, cannot? or authorize! | |
Netzke::Base.class_eval do | |
include CanCan::ControllerAdditions | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment