Rails - Number of POST request equals number of GET requests -
i'm trying make shopping cart app happen, reason seems number of post request equals sum of past requests. results in quite annoying behaviour! can't figure out why.. have idea?
applicationcontroller:
before_filter :current_delivery def current_delivery if session[:delivery_id] @delivery = delivery.find(session[:delivery_id]) else @delivery = delivery.create session[:delivery_id] = @delivery.id end end
orderitemscontroller:
def create @delivery.order_items.new(order_item_params) @delivery.save end
productscontroller:
def index @products = product.all @order_item = orderitem.new end
products index:
<% @products.each |product| %> <%= render "product_row", product: product %> <% end %>
=> partial product_row:
<%= form_for @order_item, remote: true |f| %> <%= f.number_field :quantity, value: 1, class: "form-control", min: 1 %> <%= f.hidden_field :product_id, value: product.id %> <%= f.submit "add cart", class: "btn btn-primary" %> <% end %>