Forum: Ruby on Rails replace_html and Prototype

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-01-29 06:01
(Received via mailing list)
'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
Conrad T. (Guest)
on 2007-01-29 07:10
(Received via mailing list)
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
(Guest)
on 2007-02-03 04:20
(Received via mailing list)
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
unknown (Guest)
on 2007-02-03 04:45
(Received via mailing list)
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
> <div id="addZone"></div>

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
(Guest)
on 2007-02-03 18:57
(Received via mailing list)
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?
unknown (Guest)
on 2007-02-03 21:26
(Received via mailing list)
The in-line format is exactly the same as using a template, it just
gives you a way to in-line :-) 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
(Guest)
on 2007-02-06 04:38
(Received via mailing list)
That fixed my problem. Thanks for the help.
-Reuben
This topic is locked and can not be replied to.