# AJAX in Ruby on Rails

**URL:** <https://www.ruby-forum.com/t/ajax-in-ruby-on-rails/50057>\
**Category:** Ruby\
**Created:** [December 12, 2005, 5:48pm UTC](https://www.ruby-forum.com/t/ajax-in-ruby-on-rails/50057 "2005-12-12T17:48:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [December 12, 2005, 5:48pm UTC](https://www.ruby-forum.com/t/ajax-in-ruby-on-rails/50057/1 "2005-12-12T17:48:51Z")

</div>

I’m having some trouble getting AJAX working properly for me in Rails.  
I’ve  
tried the example in “Agile Web D. with Rails” on page 391  
using  
form\_remote\_tag(), and instead of updating a

 like it should, it  
renders the form as an entirely new page. I’ve tried in on Windows XP  
and  
OS X 10.4, WEBrick and Apache, using IE and Firefox, and to no avail.

For those who don’t have the book, the problem is essentially:

I have a controller with:

def index  
end

def blah  
@stuff = ‘should print’  
render :partial =\> ‘form’  
end

index.rhtml:

### Display me!

 \<%= render(:partial =\> 'form') %\>

\_form.rhtml:  
\<% if @stuff %\>

\<%= @stuff %\>  
\<% end %\>

\<%= form\_remote\_tag(:update =\> “update\_me”, :url =\> { :action =\> :blah }  
)  
%\>  
blah blah blah  
\<%= end\_form\_tag %\>

When you submit the form, the

### Display me!
 part doesn’t show  
again.  
The render :partial =\> ‘form’ from the ‘blah’ action just renders the  
form  
and doesn’t update the “update\_me” 
 section. The WEBrick output is  
as  
follows:

127.0.0.1 - - [12/Dec/2005:10:43:28 Eastern Standard Time] “GET  
/guesswhat  
HTTP/1.1” 200 851

- → /guesswhat

127.0.0.1 - - [12/Dec/2005:10:43:28 Eastern Standard Time] “GET  
/favicon.ico  
HTTP/1.1” 200 0

- → /favicon.ico

127.0.0.1 - - [12/Dec/2005:10:43:32 Eastern Standard Time] “POST  
/guesswhat/guess HTTP/1.1” 200 623

[http://localhost:3000/guesswhat](http://localhost:3000/guesswhat) → /guesswhat/guess

Notice the difference between the first and third actions:

- → /guesswhat  
[http://localhost:3000/guesswhat](http://localhost:3000/guesswhat) → /guesswhat/guess

Does anyone know what the problem is? I hope this isn’t too  
confusing…  
it’s hard to explain. If you have the book you can run the example  
yourself  
and see what you encounter.

Thanks in advance,  
Charlie

---

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [December 12, 2005, 6:09pm UTC](https://www.ruby-forum.com/t/ajax-in-ruby-on-rails/50057/2 "2005-12-12T18:09:55Z")

</div>

Just to save someone a post… I know there’s a Rails list, but I have  
limited access to it from work (where I am now).

“Charlie S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:dnk9db$n8i$removed\_email\_address@domain.invalid…

---

<div class="post-metadata">

**Author:** ![charlieuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c89c15/32.png) [@charlieuk](https://www.ruby-forum.com/u/charlieuk)\
**Post date:** [December 12, 2005, 7:31pm UTC](https://www.ruby-forum.com/t/ajax-in-ruby-on-rails/50057/3 "2005-12-12T19:31:48Z")

</div>

Charlie S. wrote:

> Just to save someone a post… I know there’s a Rails list, but I have  
> limited access to it from work (where I am now).

Try [www.ruby-forum.com](http://www.ruby-forum.com). It mirrors the Rails mailing list and allows  
posting.
