How to use form to update the model stored in the session

hello:
I am building a shopping_cart.Before the user proceed to check out,i
want the user to be able to modify the quantity for any cart_item,so
there is a quantity update function which is a rails form in the cart
page.

  1. cart information are kept in the session,cart are made of some
    cart_items,every cart_item has title,price,quantity…attributes.
  2. cart_item is not stored in the database,but there is cart_item
    model,every cart_item object are made from the product object which has
    corresponding model and table in the database.
    My problem: when i use form to update the quantity attributes for
    some cart_item,the corresponding method can not output the expected
    result, the quantity does not changed.Who can help me?The following are
    my codes:
    <%=form_tag(:action=>“quantity_update”,:id=>cart_item)-%>
    <%=text_field :cart_item,:quantity,“size” => 10 -%>
    <%=submit_tag “recalculate”%>
    <%=end_form_tag-%>
    def quantity_update
    @cart=find_cart
    #items is an array storing the cart_items
    [email protected]{|i|i==params[:id]}
    if modified_item
    [email protected](modified_item)
    modified_item.quantity=params[:cart_item][:quantity]
    @cart.items[index]=modified_item
    return @cart
    end
    end
    private
    def find_cart
    session[:cart]||=Cart.new
    end

who can help me?

Guo Y. wrote:

who can help me?

Could it be that in

[email protected]{|i|i==params[:id]}

the i is an integer, whereas params[:id] is a string.

A simple guess.

Stephan

Thank you for reminding me !

Stephan W. wrote:

Guo Y. wrote:

who can help me?

Could it be that in

[email protected]ems.find{|i|i==params[:id]}

the i is an integer, whereas params[:id] is a string.

A simple guess.

Stephan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs