# RJS error I don't understand - multiple replace\_html

**URL:** <https://www.ruby-forum.com/t/rjs-error-i-dont-understand-multiple-replace-html/93177>\
**Category:** Rails\
**Created:** [April 28, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/rjs-error-i-dont-understand-multiple-replace-html/93177 "2007-04-28T19:27:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [April 28, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/rjs-error-i-dont-understand-multiple-replace-html/93177/1 "2007-04-28T19:27:23Z")

</div>

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 -%\>

| **To** | \<%= 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!" %\> |
| **Subject** | \<%= text\_field\_tag :subject, "Re: #{msg.subject}", :size =\> "30" %\> |
| **Message** | \<%= text\_area\_tag :body, nil, :size =\> "45x3" %\> \<%= hidden\_field\_tag :msg\_id, 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#{@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

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [April 30, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/rjs-error-i-dont-understand-multiple-replace-html/93177/2 "2007-04-30T14:54:38Z")

</div>

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
