Skip to content

Instantly share code, notes, and snippets.

@abradburne
Created March 6, 2012 09:12
Show Gist options
  • Select an option

  • Save abradburne/1985133 to your computer and use it in GitHub Desktop.

Select an option

Save abradburne/1985133 to your computer and use it in GitHub Desktop.
def require_user
unless current_user_session
respond_to do |format|
format.html { redirect_to '/hi' }
format.json do
headers["WWW-Authenticate"] = %(Basic realm="Web Password")
render :json => {'error' => 'Could not authenticate you.'}, :status => :unauthorized
end
end
return false
end
end
def require_no_user
if current_user
respond_to do |format|
format.html do
store_location
flash[:notice] = "You must be logged out to access this page"
redirect_to '/'
return false
end
format.json do
return true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment