Replace_html and Prototype


#1

'm trying to change over from Rails 1.1.6 to 1.2.1 and have discovered
that either something is wrong with Prototype of else something has
changed that I am not aware of and cannot find documentation on. (I
just joined this group, so if this has already been cussed and
discussed here or in another list then please point me in the right
direction.)

I posted this to the Spinoffs group since it seemed to be more focused
on javascript, but didn’t get any replys. I still haven’t been able to
figure out what is going on so I’m reposting it here:

===Origional Message===

I am trying to use the “replace_html” feature, and instead of
prototype
processing the generated javascript, I get a big load of “try
{Element.update( …lots of javascript garbage… ) throw e }” dumped
onto my screen in place of where the updated html should be.

I encountered the same problem when I tried to work around it by using
“replace” to swap out the whole element with updated innerHTML. The
only way I could get around this problem was to use “replace” while
changing the element id every time. (Which results in more code than
should be necessary)

Basically, whenever I try to update an element, the javascript doesn’t
get picked up by prototype unless the id of the target element gets
changed in the process.

Is this a bug or am I completely missing something here? I’ve only
been
using Rails for a couple months now, so I’m a bit new at this…

Thanks,
-Reuben


#2

Hi, after updating to 1.2.1, did you run ‘rake rails:update’ after
changing the version to 1.2.1 in the environment.rb?

-Conrad


#3

Sorry for the late reply, I’ve been gone.

Yes, I had already done that. There were finally some replies to the
origional post for this problem that I posted to the Spinoffs list,
and apparently I’m not the only one running into this problem.

-Reuben


#4

I strongly suspect your using the :update option on your remote
call???

I commented on this in another post, here is my comment from that
post:

on main.rhtml, I have:
<%= link_to_remote(‘add’, :url=>{:action=>‘openAdd’},
:update=>‘addZone’)-%> # don’t use :update for rjs calls

Don’t use the :update option with rjs calls. That constructs an
Ajax.Updater prototype object instead of the Ajax.Request object you
need for rjs calls.

On the other hand, if you only need to update one html element, I’d
leave the :update option and just return a regular partial template,
pretty sure it’s considerably faster.

Good Luck,
Tim


#5

Yes, I was using the :update option. However, I had already changed it
to the new in-line format using

update_page do |page|
  ...
end

Do I need to go back to using and RJS template if I get rid of
the :update option?


#6

The in-line format is exactly the same as using a template, it just
gives you a way to in-line :slight_smile: instead of having to create a new file
when you only need to write a couple lines.

If you use the :update option simply return regular old text/html
(e.g. a partial). Without the :update option you need to return
javascript which is where rjs, including the in-line form, comes in.

Tim


#7

That fixed my problem. Thanks for the help.
-Reuben