Skip to content

Instantly share code, notes, and snippets.

@apneadiving
Created October 8, 2011 19:10
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 apneadiving/1272720 to your computer and use it in GitHub Desktop.
Save apneadiving/1272720 to your computer and use it in GitHub Desktop.
to use Refinery with your custom devise configuration in Rails 3.1
module RefineryPatch
def self.included(base)
base.send :helper_method,
:current_refinery_user,
:refinery_user_signed_in?,
:refinery_user? if base.respond_to? :helper_method
end
def current_refinery_user
current_user
end
def refinery_user_signed_in?
user_signed_in?
end
def refinery_user?
refinery_user_signed_in? && current_refinery_user.has_role?(:refinery)
end
def authenticate_refinery_user!
authenticate_user!
end
def store_location
session[:return_to] = request.fullpath
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
end
module RestrictRefineryToRefineryUsers
def restrict_refinery_to_refinery_users
return unless !current_user.try(:has_role?, "Refinery") #current_user.try(:roles).try(:empty?) is another possibility
redirect_to main_app.root_path #this user is not a refinery user because they have no refinery roles.
return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment