Agile web development with Rails - Issue with Depot app

Hi

I"m trying to run through the sample Depot app while I learn all the
little pieces of Rails and I came upon an error I’m intrigued by.

I am adding an Ajax hook into a page view and the content is rendered
correctly (It’s the D2 - Ajax Based Cart section). The problem is, when
I use the ‘add to cart’ button it adds the element but the HTML sent
back by the Ajax call isn’t treated by the stylesheets (although all the
data is intact, it’s just in black text / normal size), if I refresh the
whole page it’s rendered fine.

I have basically ‘diffed’ the section of the cart being rendered and
there is not a single thing wrong, hence why I suspect it’s how Firefox
handle CSS applications post page processing.

Then again I see site using Ajax without this issue so I know it’s me
and not Firefox. :slight_smile:

OKay I"ll approach this from another angle.

I click to update my cart, works fine but renders the cart with no
formatting. If I refresh the whole page the formatting is fine.

Now, if I click on the “add to cart” button AGAIN I get the following
error:

RJS Error:
TypeError element has no properties

I haven’t been able to find anything on the web that deals with this
problem. (At nothing that has helped explain the issue and help me
figure out the solution)

Thanks in advance.

You are in IE right? Try firefox. This sounds like an IE problem I
ran into a while back. Failing that, use FireBug under firefox to
verify the response to the AJAX call is what you think it is, and the
CSS class or properties are being set. If you are relying on some
javascript to post-process the HTML to add CSS tags (as DOJO does),
then this may not be processing the updated HTML.

Michael

Michael L. wrote:

You are in IE right? Try firefox. This sounds like an IE problem I
ran into a while back. Failing that, use FireBug under firefox to
verify the response to the AJAX call is what you think it is, and the
CSS class or properties are being set. If you are relying on some
javascript to post-process the HTML to add CSS tags (as DOJO does),
then this may not be processing the updated HTML.

Michael

Firebug rocks thanks!

Okay The problem was a Code 13 (13" from the Monitor). Basically what
set me off the whole time is the fact that rendering on reload, and not
when I hit the Ajax button, worked. This told me something was missing
that tells the browser what style to apply.

Digging into the code being displayed (with Firebug), I notice it’s all
wrapped around a DIV Tag, but when I hit my submit button it’s not there
anymore.

The reason was this:

I had:
page.replace( “cart”, :partial => “cart”, :object => @cart )

I should have had:
page.replace_html( “cart”, :partial => “cart”, :object => @cart )

The replace method was replacing the WHOLE div not just the ‘inner html’
portion of it. Thus the first process was submitting properly (but not
rendering because it had no class ID) and the second, and subsequent
submits, were missing an ID so the Ajax couldn’t find it to ‘refresh’
it’s state…

I.E. The RJS template couldn’t find the “cart” element to update:

Love this forum. Always points me in the right direction IF doesn’t
answer the problem directly. :slight_smile:

Thanks Mike. (I hope you don’t mind being called Mike)

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