views:

301

answers:

2

Hi, In learning ruby on rails I've created a blog site. When the user adds a post via AJAX, the following rjs gets called:

page.replace_html 'posts',  :partial => @posts
page.visual_effect :Highlight, 'post_' + @post.id.to_s

However, the highlight isn't happening.. neither is any sort of effect even a hide.

Clues:

  • It works if I just do an insert_html for just the new post (but I want to update the whole list of posts at this time)
  • If I hard code the id to the next id in the sequence, it doesn't work on the post, but it does work on the next post. { ex.. hardcode post_100... no highlight on submit 100, highlight 100 on submit 101 }
  • Alert shows that 'post_' + @post.id.to_s is what is expected ( post_100, etc )

Any ideas or debugging suggestions?

Thanks, Orlando

A: 

Can you alert the innerHTML of the $("post_#{@post.id}") before the visual_effect.

Does firebug give you an error when it gets to the visual_effect?

Can you do something else, like an alert after the visual_effect line?

Have you got the required js files included?

Apie
Great suggestions.. I'm sure the required js is included because other visual effects are working. I didn't notice any errors in firebug and I didn't notice anything amiss with the HTML upon visual inspection, but I didn't try the alerts. However since my last post I decided to do away with reliance on RJS, and have everything working great using a different architecture.
Orlando
A: 

It's not really an answer to the problem, but I have since done away with reliance on rjs. Instead I'm following the pattern outlined here

http://blog.solnic.eu/2007/10/30/why-javascript-helpers-in-rails-are-evil

And now all effects are working as expected. Note that I did get the effect working when comments were added using effectively the same code that should have been working here, so I'm fairly convinced there was just some sort of weird operator error going on.

Orlando