An instance variable @x survives only for one HTTP request. When you
move from the store controller to some other controller, most likely,
you're sending another HTTP request (as opposed to an AJAX request,
typically) which clears out all instance variables. This clears out
@cart and you dont see your data.

For each request that you want your @cart to survive in, you need to
populate it with values in the controller. How can you do this? use
before_filters maybe. depends on your setup really.

On Aug 9, 8:18 pm, Konstantinos Loupos <loup...@gmail.com> wrote:
> No i dont. I am confused. Any suggestions?? Thinking of using a partial but
> i am not quite sure.
>
> On Mon, Jun 22, 2009 at 6:55 PM, Nicholas Henry 
> <nicholas.he...@gmail.com>wrote:
>
>
>
>
>
> > OK, so you know what you need to do then?
>
> > On Mon, Jun 22, 2009 at 11:40 AM, Kostas L.<loup...@gmail.com> wrote:
>
> > > Yes you are correct. I am only creating a @cart variable in the store
> > > controller.
>
> > > On Jun 22, 6:32 pm, Nicholas Henry <nicholas.he...@gmail.com> wrote:
> > >> So I guess that means in the other controllers you are not creating a
> > >> variable @cart. Does that make sense?
>
> > >> On Jun 22, 11:22 am, "Kostas L." <loup...@gmail.com> wrote:
>
> > >> > Nichola,
> > >> > unfortunately i am not able to write tests at this time.
>
> > >> > When i use debug in the store i get the products that i have in my
> > >> > cart. But when i use debug in some other controller e.g products, i
> > >> > get nothing.
>
> > >> > Kostas
>
> > >> > On Jun 22, 5:55 pm, Nicholas Henry <nicholas.he...@gmail.com> wrote:
>
> > >> > > Are you creating the @cart instance variable? Your code suggests
> > that
> > >> > > this is null:
>
> > >> > > <% if @cart %>
>
> > >> > > Try some debug code in your layout to see what @cart is,
>
> > >> > > <%= debug @cart %>
>
> > >> > > or better still right a test.
>
> > >> > > Cheers,
> > >> > > Nicholas
>
> > >> > > On Jun 22, 10:37 am, "Kostas L." <loup...@gmail.com> wrote:
>
> > >> > > > Hi guys!
> > >> > > > I have a little problem with my code. I have a div in my store
> > layout,
> > >> > > > inside of which i have my cart. When i put something in the cart i
> > get
> > >> > > > an AJAX blind_down and a replace_html. I can see the cart when i
> > am in
> > >> > > > the store controller (http://localhost/store), but when i go to
> > >> > > > another controller (e.g localhost/products/show_each/5) the cart
> > is
> > >> > > > gone.
>
> > >> > > > This is the div in the "store.html.erb" file in my layout folder:
>
> > >> > > >  <div id="side_right">
> > >> > > >       <div id="side_right_cart">
> > >> > > >         <% if @cart %>
> > >> > > >           <% hidden_div_if(@cart.items.empty?, :id => "cart" ) do
> > %>
> > >> > > >             <%= render(:partial => "cart" , :object => @cart) %>
> > >> > > >             <% end %>
> > >> > > >           <% end %>
> > >> > > >       </div>
>
> > >> > > >        <div id="side_right_login">
> > >> > > >          Login form
> > >> > > >        </div>
> > >> > > >     </div>
>
> > >> > > > Inside my "index.html.erb" in my store folder i use this method
> > for
> > >> > > > adding a product:
> > >> > > > <% form_remote_tag :url => {:action => :add_to_cart, :id =>
> > product }
> > >> > > > do %>
> > >> > > >   <%= submit_tag "Add to cart" %>
> > >> > > > <% end %>
>
> > >> > > > Also this is the AJAX code "add_to_cart.js" which is inside the
> > store
> > >> > > > folder (if this helps):
>
> > >> > > > page.select("div#notice").each { |div| div.hide}
>
> > >> > > > page.replace_html("cart", :partial=>"cart", :object=>@cart)
>
> > >> > > > page[:cart].visual_effect :blind_down if @cart.total_items==1
>
> > >> > > > page[:current_item].visual_effect :highlight,
> > >> > > >                                   :start_color => "#88ff88",
> > >> > > >                                   :endcolor => "#114411",
> > >> > > >                                   :duration => 3.0
>
> > >> > > > Any comment would be helpful!
> > >> > > > Thanx in advance
> > >> > > > Kostas
>
> --
> Κωνσταντίνος Λούπος
> loup...@gmail.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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to