Class: Spree::FavoriteProductsController
- Inherits:
-
StoreController
- Object
- StoreController
- Spree::FavoriteProductsController
- Defined in:
- app/controllers/spree/favorite_products_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/spree/favorite_products_controller.rb', line 10 def create favorite = spree_current_user.favorites.new :product_id => params[:id] if @success = favorite.save = "Product has been successfully marked as favorite" else = favorite.errors..to_sentence end respond_to do |format| format.js end end |
#destroy ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/controllers/spree/favorite_products_controller.rb', line 22 def destroy if @product_id = Spree::Product.where(:permalink => params[:id]).first.try(:id) @favorite_product = Spree::Favorite.where("user_id = ? and product_id = ?", spree_current_user.id, @product_id).first @success = @favorite_product.try(:destroy) else @success = false end end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/spree/favorite_products_controller.rb', line 6 def index @favorite_products = spree_current_user.favorite_products end |