Frederick Cheung wrote:
> On Oct 10, 11:46�am, Jay Pangmi <[EMAIL PROTECTED]>

> The same as retrieving any other value from the sesion (ie
> session[:cart])
> 
> Fred

Actually, params[:cart] is derived from <%form_for :cart ...%> Inside
this, there are textfields corresponding to "carts" table and hence I
could save the values in the form and I'm doing this way:

CONTROLLER:
def add_to_cart
    @cart_items=[]
    @cart=find_cart(params[:cart])
    if @cart.save
      @cart_items << @cart
    else
      flash[:notice]="Details couldn't be saved"
    end
end

private

  def find_cart(cartobj)
    session[:cart] ||= Cart.new(cartobj)
  end

I'm using @cart_items array just because I couldn't iterate through the
@cart to list all the entered details in the add_to_cart.rhtml as:

VIEW:
<h1>Your details:</h1>
<ul>
  <%for item in @cart_items%>
    <li><%=item.campsite%></li>
    <li><%=item.arrival_date%></li>
    <li><%=item.nights%></li>
    <li><%=item.parents%></li>
    <li><%=item.children%></li>
    <li><%=item.family_claim%></li>
  <%end%>
</ul>
<%=button_to "Empty cart", :action => :empty_cart%>

So, now when I click the "add to cart" button in the view everything
gets added to the "carts" table and I'm taken to add_to_cart.rhtml with
the list of details. Now in this case how can i empty it when empty_cart
action is triggered for this specific session?

thanks fred.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to