small medium large xlarge

Generic-user-small
20 Jun 2008, 17:17
Michal Nedoszytko (3 posts)

Hello there,

I’m happily making my way through the 3rd edition beta and am sure that the money was well worth it. However I’ve stumbled upon a problem with changing the visibility of the cart div while adding first product. I’m quite convinced that I’ve followed every stop so far.

Here we go:

First - if there are no products the cart is hidden using the

def hidden_div_if(condition, attributes = {}, &block)
    if condition
      attributes["style"] = "display: none"
    end
    content_tag("div", attributes, &block)
end

in StoreHelper

which is incorporated in store layout

like this

      <% hidden_div_if(@cart.items.empty?, :id => "cart") do %>
        <%= render(:partial => "cart", :object => @cart) %>
      <% end %>

this works fine and makes the display:none upon loading the page when cart is empty and upon loading the page when cart contains items.

Now the problem is that when i press Add to Cart the items indeed are added to the session cart via ajax call, but the div id=’cart’ doesn’t change the display attribute value. Only after reloading the page manually the div is shown.

I am well aware that the blind_down of the script.aculo.us should be executed while adding the first item to the cart here is the content of add_to_cart.js.rjs

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,
                                  :startcolor => "#88ff88",
                                  :endcolor => "#114411"

rails version: 2.1.0 ruby: 1.8.7

However I cannot see it working. Is it something wrong in the book, or I am mistaking something? I’ve checked 3 times that I’ve followed the instructions and even downloaded the sources from repository. However errare humanum est. Could you correct me?

Nedo

Generic-user-small
20 Jun 2008, 19:32
James West (104 posts)

Hi

My add_to_cart.js.rjs looks like this

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, :startcolor => “#88ff88” , :endcolor => “#114411”

Don’t know if your problem is due to not having finished the section yet but this worked very well for me on the same versions as you have :-)

Hope it helps

Generic-user-small
20 Jun 2008, 19:50
Michal Nedoszytko (3 posts)

Hello James,

Thank you very much for swift response. The rjs actually seems to be responding and the line responsible for emerging the cart is lookalike the same

page[:cart].visual_effect :blind_down if @cart.total_items == 1

However the problem is that on initial state the div is hidden

<div id="cart" style="visibility: hidden">

and after applying the BlindDown effect - which seems to be working it still stays hidden the only thing that changes is overflow:visible, which seems to be applied by the effect, nevertheless it doesn’t make the div visible

<div style="overflow: visible; visibility: hidden;" id="cart"><div class="cart-title">Twój kosz</div>
<table>
  
<tbody><tr id="current_item" style="background-image: none; background-color: transparent;">

  <td>1×</td>
  <td>Pragmatic Project Automation</td>
  <td class="item-price">$29.95</td>
</tr>



  <tr class="total-line">
    <td class="total-cell">$29.95</td>
  </tr>
</tbody></table>

<form class="button-to" action="/store/empty_cart" method="post"><div><input type="submit" value="Empty cart"/><input type="hidden" value="99debd5297a4789500d648342d21453ebbbf4378" name="authenticity_token"/></div></form>
</div>

I’m not sure what’s responsible for the problem -> my browsers (ff2 and ie6) handle ajax perfectly. No js errors on debugger.

Just -> the div stays hidden. I’ve been trying to fix it with page.show ‘cart’ if @cart.total_items == 1 in the rjs but it doesn’t work either.

Still need help

Nedo

Generic-user-small
20 Jun 2008, 20:01
Michal Nedoszytko (3 posts)

GOT IT!

For some stupid reason i have used:

visibility: hidden

instead of

display: none

on the cart

The BlindDown effect didn’t change the visibility property - that’s why the cart stayed hidden.

My mistake - I got used to using the visibility method. I beg your forgiveness for wasting the forum space.

Yours, Nedo

You must be logged in to comment