ruby on rails - How do I save information to a model on Devise.sessions#destroy? -


i'm using devise , piggybak rails project , piggybak uses cookie named cart store user cart. problem piggybak doesn't destroy cookie on user sign_out so, if sign_in user, uses same cookie , therefore, same cart.

i want solve storing cookie value user model, enabling cart on sign_in. did overriding devise.sessions#destroy method save cookie value on user , destroy cookie:

# app/controllers/users/sessions_controller.rb  class users::sessionscontroller < devise::sessionscontroller    def destroy     current_user.add_cart_cookie(cookies['cart']['value'])     cookies['cart'] = { value: '', path: '/' }     super   end end 

routing right in routes:

# config/routes.rb  ...  devise_for :users, controllers: { sessions: 'users/sessions' }  ... 

and creating method add_cart_cookie user model:

# app/models/user.rb  class user < activerecord::base  ...    def add_cart_cookie(value)     self.cart_cookie = value   end  ...  end 

but not working, destroy cookie don't save on user model. why happening?

did it, thank @marian.

what did change add_cookie_cart method accept parameter:

# app/models/user.rb  class user < activerecord::base  ...    def add_cart_cookie(value, password)     self.cart_cookie = value     self.password = password     self.password_confirmation = password     self.save   end  ...  end 

and changed session#destroy accordingly:

class users::sessionscontroller < devise::sessionscontroller    def destroy     current_user.add_cart_cookie(cookies['cart']['value'], current_user.password)     cookies['cart'] = { value: '', path: '/' }     super   end end 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -