I’m working on a webshop and i create a session called cart for the
Cart. (
session[:cart] )
The session stores the quantities of the products in cart.
Please help me how can i delete az item from the session? (remove from
cart…)
That entirely depends on what you put into the session.
If you store a number:
session[:cart] = 123
you can just set it to nil:
session[:cart] = nil
(or 0 or something…)
If you store some array:
session[:cart] ||= []
session[:cart] << 1
session[:cart] << 2
just delete from it:
session[:cart].delete(1)
session[:cart] #=> [2]
After each request the data in the session object will be marshaled and
stored, then loaded upon the next request.
Hope that helps.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.