daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ItemsController < ApplicationController
  2.  
  3.   def index
  4.     if(!session[:cart].nil?)
  5.       items = session[:cart].keys
  6.       @products = Product.where(:id => items)
  7.     end
  8.   end
  9.  
  10.   def add
  11.    
  12.     session[:cart] ||= {}
  13.    
  14.     product_id = params[:product_id].to_i
  15.    
  16.     session[:cart][product_id] ||= 0
  17.     session[:cart][product_id] += 1
  18.    
  19.     redirect_to(items_url)
  20.   end
  21.  
  22.   def destroy
  23.     product_id = params[:product_id].to_i
  24.    
  25.     if(session[:cart][product_id] == 1)
  26.       session[:cart].delete(product_id)
  27.     else
  28.       session[:cart][product_id]-=1
  29.     end
  30.  
  31.     redirect_to(items_url)
  32.   end
  33.  
  34. end
RAW Paste Data
Top