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

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.
Befa945ac6d3bf13c4b41657e8558f85?d=identicon&s=25 Mike Dershowitz (dersh53)
on 2007-04-28 19:27
Hello:

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 => msg.id } %> |

the "forward" function it calls is here:

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

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">
    <tr>
      <td><b>To</b></td>
      <td align="left"><%= text_field_tag :to, nil, :size => "15" %>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <%= submit_tag "Send!" %>
    </td>
    </tr>
    <tr>
      <td><b>Subject</b></td>
      <td align="left"><%= text_field_tag :subject, "Re:
#{msg.subject}", :size => "30" %>
    </td>
    </tr>
      <td><b>Message</b></td>
      <td><%= text_area_tag :body, nil, :size => "45x3" %>
    <%= hidden_field_tag :msg_id, msg.id %>
    </td>
    </tr>
  </table>
</span>
<% 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#{@reply_to.id}"].update :partial => 'empty'
  end

(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!

Mike
83ca41657a99b65d99889abe712ba5e2?d=identicon&s=25 Jason Roelofs (Guest)
on 2007-04-30 14: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#{@reply_to.id}", :partial => 'empty'
 end

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

Jason
This topic is locked and can not be replied to.