Q:

Button "Add" behavier is very strange

Application has Add to Cart button, which creates new @line_item (code is based on Agile Development with Rails).
I added an Ajax-feature, so Add to Cart doesn't reload page, and adds @line_item to @cart.
But Rails does this three times per once button push! 
I push "Add to Cart", and it adds 3 items.
Also, when I emty cart, it asks me three times "Are you sure?"
Have no idea, what may cause these, any ideas?
def create
@cart = current_cart
product = Product.find(params[:product_id]) 
@line_item = @cart.add_product(product.id)
respond_to do |format|
if @line_item.save
format.html { redirect_to(store_url) }
format.js
format.xml { render :xml => @line_item,
:status => :created, :location => @line_item }
else
format.html { render :action => "new" }
format.xml { render :xml => @line_item.errors,
:status => :unprocessable_entity }
end
end
end

button:
<%= button_to 'Add to Cart' , line_items_path(:product_id => product),:remote => true %>

create.js.erb:
$('#cart').html("<%= escape_javascript(render(@cart)) %>");

_cart.html.erb template:
<div class="cart_title" >Your Cart</div>
<table>
<%= render(cart.line_items) %>
<tr class="total_line" >
<td colspan="2" >Total</td>
<td class="total_cell" ><%= number_to_currency(cart.total_price) %></td>
</tr>
</table>
<%= button_to 'Empty cart' , cart, :method => :delete,
:confirm => 'Are you sure?' %>

_line_item.html.erb template:
<tr>
<td><%= line_item.quantity %>&times;</td>
<td><%= line_item.product.title %></td>
<td class="item_price" ><%= number_to_currency(line_item.total_price) %></td>
</tr>

A:

Problem solved.
On my view application layout I thought it is right to do like that
<!DOCTYPE html>
<html>
<head>
  <title>Store</title>
  <%= stylesheet_link_tag "store" %>
  <%= javascript_include_tag 'application' %>
  <%= csrf_meta_tags %>
  <title>Cart</title>
  <%= stylesheet_link_tag "carts" %>
  <%= javascript_include_tag 'cart' %> #this
  <%= csrf_meta_tags %>

Actually, i suppose once you have used "application" on main page, #this dublicates execution of JS code

