# Strange RJS behavior

**URL:** <https://www.ruby-forum.com/t/strange-rjs-behavior/63195>\
**Category:** Rails\
**Created:** [June 13, 2006, 3:53am UTC](https://www.ruby-forum.com/t/strange-rjs-behavior/63195 "2006-06-13T03:53:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 13, 2006, 3:53am UTC](https://www.ruby-forum.com/t/strange-rjs-behavior/63195/1 "2006-06-13T03:53:09Z")

</div>

I used RJS extensively in my last web app with no problem.

I’m just beginning a new one and having a very odd problem.

The called method, get\_names, retrieves some values from the database,  
then ends:

render :layout =\> false

the get\_names.rjs file is rendered into Javascript, but then is just  
dumped as Javascript (text) into the browser:

e.g:

try {  
Element.update(“this\_panel”, “”);  
new Insertion.Bottom( … );  
} catch (e) { alert(‘RJS error:\n\n’

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 13, 2006, 12:22pm UTC](https://www.ruby-forum.com/t/strange-rjs-behavior/63195/2 "2006-06-13T12:22:03Z")

</div>

Does the link\_to\_remote by any chance have an :update =\> ‘this\_panel’ in  
it ? That would take the reuslt of the Ajax call and update the div.  
I often make this mistake if I start with an update and replace it with  
RJS.

Alan

Chris H. wrote:

> the get\_names.rjs file is rendered into Javascript, but then is just  
> dumped as Javascript (text) into the browser:

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 14, 2006, 2:27am UTC](https://www.ruby-forum.com/t/strange-rjs-behavior/63195/3 "2006-06-14T02:27:26Z")

</div>

Alan F. wrote:

> Does the link\_to\_remote by any chance have an :update =\> ‘this\_panel’ in  
> it ? That would take the reuslt of the Ajax call and update the div.  
> I often make this mistake if I start with an update and replace it with  
> RJS.
> 
> Alan
> 
> Chris H. wrote:
> 
> > the get\_names.rjs file is rendered into Javascript, but then is just  
> > dumped as Javascript (text) into the browser:

Alan–no it’s just this:

```
		<%= form_remote_tag :url => { :controller => "name", :action => 

```

“get\_name”} %\>  
Enter your name:  
\<%= text\_field “name\_input”,“name”, :size =\> 20 %\>  
\<%= end\_form\_tag %\>

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 14, 2006, 6:42am UTC](https://www.ruby-forum.com/t/strange-rjs-behavior/63195/4 "2006-06-14T06:42:50Z")

</div>

Chris H. wrote:

> > 
> 
> ```
> <label for="name_input">Enter your name:</label>
> <%= text_field "name_input","name", :size => 20 %>
> <%= end_form_tag %>
> 
> ```

Can you paste your .rjs file? Like Alan I have seen this before when  
setting :update but since you are not doing that the problem may be in  
the rjs.

Matthew M.  
[blog.mattmargolis.net](http://blog.mattmargolis.net)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 15, 2006, 11:43am UTC](https://www.ruby-forum.com/t/strange-rjs-behavior/63195/5 "2006-06-15T11:43:32Z")

</div>

Alan F. wrote:

> > Can you paste your .rjs file? Like Alan I have seen this before when  
> > setting :update but since you are not doing that the problem may be in  
> > the rjs.
> 
> One other problem might be content type. If you copy the code from the  
> rjs into the action and use render :update instead, does it work there ?
> 
> [Codefluency.com](http://codefluency.com/articles/2006/05/27/rails-views-render-update-not-rjs/)
> 
> A.

Also, did you remember to add the javascript tags to the layout ?

A.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 14, 2006, 11:38am UTC](https://www.ruby-forum.com/t/strange-rjs-behavior/63195/6 "2006-06-14T11:38:18Z")

</div>

> Can you paste your .rjs file? Like Alan I have seen this before when  
> setting :update but since you are not doing that the problem may be in  
> the rjs.

One other problem might be content type. If you copy the code from the  
rjs into the action and use render :update instead, does it work there ?

[http://codefluency.com/articles/2006/05/27/rails-views-render-update-not-rjs/](http://codefluency.com/articles/2006/05/27/rails-views-render-update-not-rjs/)

A.
