# RJS and Action Renders but page doesn't update

**URL:** <https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614>\
**Category:** Rails\
**Created:** [July 16, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614 "2006-07-16T22:07:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 16, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/1 "2006-07-16T22:07:24Z")

</div>

All,

I am trying to perform a simple ajax task and am having some  
difficulties with the page showing the response. The action performs,  
but no response on the page.

I have found examples on the web and I believe I have copied and  
pasted exactly what works from the demo site. However, on my system it  
isn’t finishing. For a simple test, I have limited it down to an alert.

\<%= link\_to\_remote ‘Doing a JavaScript alert’,  
:url =\> {:action =\> ‘do\_alert’} %\>

Leaving out the rest of the code (controller, etc…) because it is  
irrelevant. If I modify the above to this:

\<%= link\_to\_remote ‘Doing a JavaScript alert’,  
:url =\> {:action =\> ‘do\_alert’}, :complete =\>  
“eval(request.responseText)” %\>

It works. As such, I know the response is coming back but for some  
reason the page doesn’t display my results. From what I understand, the  
:complete should not be required.

Further, I don’t want to do an alert - I want to change some text and  
show an image while an action is in progress, then remove the image when  
the action is completed. I am only doing the alert as something simple  
until I figure out why the page isn’t refreshing properly. Any pointers  
on what I am doing wrong?

Thank you,

Michael

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 16, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/2 "2006-07-16T22:10:34Z")

</div>

Michael wrote:

> It works. As such, I know the response is coming back but for some
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

It would be really helpful if you could paste your rjs and the relevant  
part of the controller.  
If you are using Firefox then I recommend that you get Firebug and check  
out the actual request and response that your link is causing.

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

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 17, 2006, 12:32am UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/3 "2006-07-17T00:32:44Z")

</div>

Matthew M. wrote:

> Michael wrote:
> 
> > It works. As such, I know the response is coming back but for some
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> It would be really helpful if you could paste your rjs and the relevant  
> part of the controller.  
> If you are using Firefox then I recommend that you get Firebug and check  
> out the actual request and response that your link is causing.
> 
> Matthew M.  
> [blog.mattmargolis.net](http://blog.mattmargolis.net)

Hi Matthew,

do\_alert.rjs:

page.alert “This is a test alert!!!”

Controller:

def do\_alert

end

That’s pretty basic, huh? I have tried a few different examples with no  
luck. I’m sure I’m missing something basic!

Your help is appreciated.

Michael

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 17, 2006, 1:52am UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/4 "2006-07-17T01:52:22Z")

</div>

On Monday, July 17, 2006, at 12:32 AM, Michael wrote:

> > It would be really helpful if you could paste your rjs and the relevant
> 
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)  
> I presume you are including the appropriate javascript files in your  
> layout.

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 17, 2006, 4:36am UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/5 "2006-07-17T04:36:24Z")

</div>

Michael wrote:

> Kevin O. wrote:
> 
> > On Monday, July 17, 2006, at 12:32 AM, Michael wrote:
> > 
> > > > It would be really helpful if you could paste your rjs and the relevant
> > > 
> > > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)  
> > > I presume you are including the appropriate javascript files in your  
> > > layout.
> > 
> > \_Kevin  
> > [www.sciwerks.com](http://www.sciwerks.com)
> 
> Kevin,
> 
> Yes - I have the javascripts included as per  
> \<%= javascript\_include\_tag :defaults %\>
> 
> Remember, the :complete =\> “eval(request.responseText)” statement allows  
> me to see the returned code.
> 
> Thank you…
> 
> Michael

Okay - Now I am limiting this to just one question! I have changed from  
the “alert” test to something more along the lines of what I want. I’m  
updating a div with something and adding a visual effect. I spent the  
10 bucks and bought Cody F.'s eBook titled “RJS Templates for Rails”  
and cut and paste the very first sample. It did not work, as suspected.  
I simply added the ":complete =\> “eval…” and it worked fine. So I  
guess my only question is why am I having to put the :complete…  
portion in my code when it doesn’t appear that other samples, including  
Cody’s, require that?

Thanks,

Michael

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 17, 2006, 6:21am UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/6 "2006-07-17T06:21:09Z")

</div>

Michael wrote:

> > > I presume you are including the appropriate javascript files in your  
> > > Remember, the :complete =\> “eval(request.responseText)” statement allows  
> > > the “alert” test to something more along the lines of what I want. I’m
> 
> Michael

What version of Rails are you running? Have you tried using inline rjs  
in your controller? If you can get Firefox and Firebug and post the  
XMLHTTPrequest and response for us that would be great.

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

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 17, 2006, 6:23pm UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/7 "2006-07-17T18:23:15Z")

</div>

Matthew M. wrote:

> Michael wrote:
> 
> > > > I presume you are including the appropriate javascript files in your  
> > > > Remember, the :complete =\> “eval(request.responseText)” statement allows  
> > > > the “alert” test to something more along the lines of what I want. I’m
> > 
> > Michael
> 
> What version of Rails are you running? Have you tried using inline rjs  
> in your controller? If you can get Firefox and Firebug and post the  
> XMLHTTPrequest and response for us that would be great.
> 
> Matthew M.  
> [blog.mattmargolis.net](http://blog.mattmargolis.net)

Hi Matthew,

I’m on Rails 1.1.2. I did try inline RJS as well with same results. To  
date, I haven’t used Firebug but I will install it sometime this week  
and play around with it to see what is going on. For now, I have  
working what I need and actually ended up needing to put in the  
:complete anyway (along with :loading) in order to set the progress  
indicator properly and hide it upon completion.

Cody’s eBook on RJS Templates had an example of exactly what I was  
trying to do, so it was worth the $10.00. I have a long running action  
(pdf file creation that gets emailed to a user) and simply wanted to  
allow the user to do this via an ajax call so they could get a visible  
clue that they not only clicked the button but that it was doing  
something in the background.

I’m beginning to think that the :complete must be a default setting that  
isn’t being set in my application. It was mostly frustrating to me  
because I was using examples found on the web w/o this setting and  
couldn’t get anything to work (actually, to display the updated values).  
I guess for me it is more of a “why didn’t it work” question.

Having worked with XMLHTTPRequests many years ago via Javascript and  
MSXMLHTTP, I can say that I LOVE the RJS functionality. It is so clean  
and once you figure out how to use it - it is very cool.

Regards,

Michael

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [July 17, 2006, 3:34am UTC](https://www.ruby-forum.com/t/rjs-and-action-renders-but-page-doesnt-update/98614/8 "2006-07-17T03:34:43Z")

</div>

Kevin O. wrote:

> On Monday, July 17, 2006, at 12:32 AM, Michael wrote:
> 
> > > It would be really helpful if you could paste your rjs and the relevant
> > 
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)  
> > I presume you are including the appropriate javascript files in your  
> > layout.
> 
> \_Kevin  
> [www.sciwerks.com](http://www.sciwerks.com)

Kevin,

Yes - I have the javascripts included as per  
\<%= javascript\_include\_tag :defaults %\>

Remember, the :complete =\> “eval(request.responseText)” statement allows  
me to see the returned code.

Thank you…

Michael
