Skip to content

Instantly share code, notes, and snippets.

@scho
Created August 2, 2012 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scho/3237417 to your computer and use it in GitHub Desktop.
Save scho/3237417 to your computer and use it in GitHub Desktop.
Initializer for cancan within Netzke in order to use cancan helpers
# 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