Re: session question..

Jay Pangmi
Fri, 10 Oct 2008 11:13:21 -0000

Frederick Cheung wrote:
> On Oct 10, 11:46�am, Jay Pangmi
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>

> 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:
Your details:

  <%for item in @cart_items%>
<%=item.campsite%>
<%=item.arrival_date%>
<%=item.nights%>
<%=item.parents%>
<%=item.children%>
<%=item.family_claim%>
  <%end%>

<%=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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com