Skip to content

Instantly share code, notes, and snippets.

@guillermo
Created March 14, 2011 18:20
Show Gist options
  • Save guillermo/869582 to your computer and use it in GitHub Desktop.
Save guillermo/869582 to your computer and use it in GitHub Desktop.
module RequireLoggedUser
protected
def require_logged_user!
before_filter do
return true if current_user.present?
# if the method hasn't returned, there is no user logged in!
# flash a warning and redirect the user to the log in page
flash[:warning] = "You must log in before proceeding!"
redirect_to new_user_session_path and return
end
def self.extend_object(controller)
super
controller.send(:require_logged_user!)
end
end
class StoreCheckoutsController < ApplicationController
extend RequireLoggedUser
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment