# RJS call from controller issues javascript that doesn't get

**URL:** <https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621>\
**Category:** Rails\
**Created:** [March 29, 2006, 12:41am UTC](https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621 "2006-03-29T00:41:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ovidiu\_EFTIMIE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b9bd4f/32.png) [@Ovidiu\_EFTIMIE](https://www.ruby-forum.com/u/Ovidiu_EFTIMIE)\
**Post date:** [March 29, 2006, 12:41am UTC](https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621/1 "2006-03-29T00:41:55Z")

</div>

Hi,  
I’m on Rails 1.1 and I have a problem wit RJS  
In my cotroller i have  
==\>\>\>  
def show  
@contact = Contact.find(params[:id])  
render :update do |page|  
page[:contactInfo].replace\_html :partial=\>“contactInfo”  
end  
end  
\<\<\<===

And my contactInfo partial looks like this and it’s placed inside a div  
element  
==\>\>\>

| **\<%=h @contact.first\_name%\>** &nbsp; \<%=h @contact.last\_name%\> |
| \<%=h @contact.address.address%\> | |
| Tel : \<%h= @contact.address.phone%\>&nbsp; Fax : \<%h= @contact.address.fax%\>&nbsp; E-mail : \<%h= @contact.address.email%\>&nbsp; | |

\<\<\<==

The thing is that my show method gets called and it returns a java  
script call  
$(“contactInfo”).update("

\n \n \n \n \n \n \n \n \n

| **aaa** &nbsp; aaa |
| aaa | \n |
| Tel : &nbsp;\n Fax : &nbsp;\n E-mail : &nbsp;\n | \n |

 ");

Can anyone tell me how to get my div updated ?

Thanx,  
Ovidiu

---

<div class="post-metadata">

**Author:** ![Ovidiu\_EFTIMIE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b9bd4f/32.png) [@Ovidiu\_EFTIMIE](https://www.ruby-forum.com/u/Ovidiu_EFTIMIE)\
**Post date:** [March 29, 2006, 1:02am UTC](https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621/2 "2006-03-29T01:02:22Z")

</div>

You have not specified the id element to update in replace\_html method  
(which expects an id).  
You should replace this line that way:

page.replace\_html “contactInfo”, :partial =\> “contactInfo”

---

<div class="post-metadata">

**Author:** ![Ovidiu\_EFTIMIE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b9bd4f/32.png) [@Ovidiu\_EFTIMIE](https://www.ruby-forum.com/u/Ovidiu_EFTIMIE)\
**Post date:** [March 29, 2006, 8:20am UTC](https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621/3 "2006-03-29T08:20:49Z")

</div>

Actually I have done as you suggested and the result is the same.  
page[:contactInfo].replace\_html :partial=\>“contactInfo” is also valid.

---

<div class="post-metadata">

**Author:** ![Ovidiu\_EFTIMIE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b9bd4f/32.png) [@Ovidiu\_EFTIMIE](https://www.ruby-forum.com/u/Ovidiu_EFTIMIE)\
**Post date:** [March 29, 2006, 8:00pm UTC](https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621/4 "2006-03-29T20:00:20Z")

</div>

- Are you changing the Content-Type of the response? It needs to be  
‘text/javascript’ to be automatically evaluated by Prototype.

- Your div has the id ‘contactInfo’?

- Make sure you aren’t using the :update option in your remote function  
call.

- Did you run ‘rake rails:update’ to update your JavaScripts?

- Does popping an alert box work?  
page.alert(‘RJS works!’)

On 3/29/06, Ovidiu EFTIMIE [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > end  
> > > \<%=h @contact.address.address%\>  
> > > The thing is that my show method gets called and it returns a java script call
> > > 
> > > * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![Ovidiu\_EFTIMIE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b9bd4f/32.png) [@Ovidiu\_EFTIMIE](https://www.ruby-forum.com/u/Ovidiu_EFTIMIE)\
**Post date:** [March 30, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621/5 "2006-03-30T23:22:25Z")

</div>

Cody … you’re the man:). Thanx a lot !!!  
Actualy I was having tha update option set in my remote function call  
Now it looks like this

\<%= remote\_function(:complete =\>“new Effect.Highlight(‘contactInfo’ )”,  
:url =\> { :action =\>  
‘show’,:id=\>contact.id}) %\>"

---

<div class="post-metadata">

**Author:** ![Ovidiu\_EFTIMIE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b9bd4f/32.png) [@Ovidiu\_EFTIMIE](https://www.ruby-forum.com/u/Ovidiu_EFTIMIE)\
**Post date:** [March 29, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/rjs-call-from-controller-issues-javascript-that-doesnt-get/89621/6 "2006-03-29T20:15:37Z")

</div>

To clarify:

> - Are you changing the Content-Type of the response? It needs to be  
> ‘text/javascript’ to be automatically evaluated by Prototype.

Make sure you aren’t overwriting the Content-Type. RJS will set it  
for you automatically.

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)
