In the depot example we use a “Empty cart” button to empty the cart.
However, Instead of clicking the “Empty Cart” button, we want to call
a script from inside a .SWF(Flash) object to do it.
How do we write a .rb script to do something in the Rails
environment?
-Frank
~/rails/depot/app/controllers/store_controller.rb
class StoreController < ApplicationController
before_filter :find_cart, :except => :empty_cart
def index
@products = Product.find_products_for_sale
@cart = find_cart
end
def add_to_cart
begin
product = Product.find(params[:id])
rescue ActiveRecord::RecordNotFound
logger.error(“Attempt to access invalid product #{params[:id]}”)
redirect_to_index(“Invalid product”)
else
@cart = find_cart
@current_item = @cart.add_product(product)
redirect_to_index unless request.xhr?
end
end
def empty_cart