# RJS not executed

**URL:** <https://www.ruby-forum.com/t/rjs-not-executed/132783>\
**Category:** Rails\
**Created:** [March 24, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/rjs-not-executed/132783 "2008-03-24T18:05:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![greenski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e47774/32.png) [@greenski](https://www.ruby-forum.com/u/greenski)\
**Post date:** [March 24, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/rjs-not-executed/132783/1 "2008-03-24T18:05:29Z")

</div>

Hello,

I began a ruby application recently and I try to integrate Ajax touchs  
but I got a strange problem here.

In my view app/views/messages/index.rthml, I’ve got a simple link to a  
remote function and a container

[code]\<%= link\_to\_remote “Refresh”, :url =\> { :controller =\> “messages”,  
:action =\> “get\_messages”, :method =\> “get”, :page =\>  
@messages.current\_page }, :before =\> “Element.show(‘wait’)”, :complete  
=\> “Element.hide(‘wait’)” %\>

\<%= render :partial =\> "shared/messages/messages", :object =\> @messages %\>
[/code]

In my controller app/controllers/messages\_controller.rb, I’ve got the  
associated method :

```auto
  def get_messages
  @messages = Message.paginate :page => params[:page], :per_page =>
Message.per_page,
     :limit => Message.per_page,
     :order => 'created_at DESC'
  end
```

and I finally have a RJS file name app/views/messages/get\_messages.rjs  
with the following code:

```auto
page.replace_html ('messages_container', :partial =>
"shared/messages/messages", :object => @messages)
```

The problem is that the RJS file is _never_ used/called by RoR and I do  
not understand why.

I’m sure the get\_messages method in the controller is called and  
executed because when I put the JS instructions inthere, that’s work :

```auto
  def get_messages
  @messages = Message.paginate :page => params[:page], :per_page =>
Message.per_page,
     :limit => Message.per_page,
     :order => 'created_at DESC'
  render(:update) { |page|
     page.replace_html 'messages_container', :partial =>
'shared/messages/messages', :object => @messages
  }
  end
```

I should be able to put the JS code in the RJS file, but it is ignored.  
When I tried to add an :update id in my link\_to\_remote call, the RJS is  
read but the container is replaced by the generated javascript code (not  
executed so).

Thx in advance if somebody has an idea !
