surely , but i warn you that that tutorial is very old, there are better way
to do everything now.
[code]
<!-- store_controller#index -->
<% form_remote_tag :url => { :action => 'add_to_cart', :id => product }
do %>
<%= text_field_tag :quantity%>
<%= submit_tag "Add to Cart" %>
<% end %>
[/code]
[code]
# store_controller.rb
def add_to_cart
product = Product.find(params[:id])
@cart = find_cart
@current_item = @cart.add_product(product)
# render xhr request
[/code]
[code]
# model cart.rb / no DB table
def add_to_cart(product)
current_item = @items.find {|item| item.product == product}
if current_item
params[:quantity].blank? ? current_item.increment_quantity :
current_item.quantity = params[:quantity]
else
current_item = CartItem.new(product)
unless params[:quantity].blank? current_item.quantity =
params[:quantity]
@items << current_item
end
current_item
end
[/code]
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.