Skip to content

Instantly share code, notes, and snippets.

@a-chernykh
Created November 9, 2010 20:30
Show Gist options
  • Save a-chernykh/669746 to your computer and use it in GitHub Desktop.
Save a-chernykh/669746 to your computer and use it in GitHub Desktop.
class CustomDevise::SessionsController < Devise::SessionsController
def create
anonymous_cart = Cart.where(:security_hash => session[:security_hash]).last unless session[:security_hash].nil?
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message :notice, :signed_in
if anonymous_cart && !anonymous_cart.user_id?
resource.cart.delete if resource.cart
anonymous_cart.update_attribute(:user_id, resource.id)
end
sign_in_and_redirect(resource_name, resource)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment