Forum: Ruby on Rails RJS error I don't understand - multiple replace_html

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Mike D. (Guest)
on 2007-04-28 21:27

I've got a remote-link-to that's replaacing a div section quite nicely.
the HTML that get's injected into the form in the first place has a form
in it.  Here's waht gets injected in a div on a page:

The link_to_remote that does this is here:

<%= link_to_remote "Forward",
                        :url => { :controller => 'messages', :action =>
'forward', :id => } %> |

the "forward" function it calls is here:

  def forward
    @message = Message.find(params[:id])
  render :update do |page|
    page["reply-forward#{}"].replace_html :partial =>
'fmessage', :locals => { :msg => @message}

The partial that gets injected is here ("_fmessage.rhtml"):

<% form_tag '/messages/create_forward' do -%>
<span class="boldTextBlk">
<table  border="0" cellpadding="1" cellspacing="1">
      <td align="left"><%= text_field_tag :to, nil, :size => "15" %>
        <%= submit_tag "Send!" %>
      <td align="left"><%= text_field_tag :subject, "Re:
#{msg.subject}", :size => "30" %>
      <td><%= text_area_tag :body, nil, :size => "45x3" %>
    <%= hidden_field_tag :msg_id, %>
<% end %>

And the method that the submit tag calls is quite simple - the DB
inserts it does work fine.  But what doesn't, is when I try and
essentially empty-out the original div that the partial gets put into.
Here's the code I'm trying:

  render :update do |page|
    page["reply-forward#{}"].update :partial => 'empty'

(NOTE: I also tried replace_html, but that didn't work either.  The
error it's giving is:

try {
$("reply-forward23").update({partial: "empty"});
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('$(\"reply-forward23\").update({partial: \"empty\"});'); throw e }

I'm sure this an error others have encountered.  I tried to give you a
complete picture.  I'm just not sure why I can re-replace (essentially,
that's what I'm doing).

Thank you very much in advance for your help!

Jason R. (Guest)
on 2007-04-30 16:54
(Received via mailing list)
The proper form of replace_html is:

page.replace_html dom_id, *render_options

In your case:

render :update do |page|
   page.replace_html "reply-forward#{}", :partial => 'empty'

Anything that isn't recognized by the JavascriptHelper gets turned
into Javascript (e.g. your update method).

This topic is locked and can not be replied to.