Created
October 8, 2011 19:10
-
-
Save apneadiving/1272720 to your computer and use it in GitHub Desktop.
to use Refinery with your custom devise configuration in Rails 3.1
This file contains hidden or 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
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 |
This file contains hidden or 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
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