Forum: Ruby on Rails AJAX in Ruby on Rails

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E7ba2984144107d47f82c14968324fa7?d=identicon&s=25 Charles Squires (Guest)
on 2005-12-12 18:09
(Received via mailing list)
I'm having some trouble getting AJAX working properly for me in Rails.
tried the example in "Agile Web Development with Rails" on page 391
form_remote_tag(), and instead of updating a <div> like it should, it
renders the form as an entirely new page. I've tried in on Windows XP
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

def blah
@stuff = 'should print'
render :partial => 'form'

<h3>Display me!</h3>
<div id="update_me">
<%= render(:partial => 'form') %>

<% if @stuff %>
<p> <%= @stuff %>
<% end %>

<%= form_remote_tag(:update => "update_me", :url => { :action => :blah }
blah blah blah
<%= end_form_tag %>

When you submit the form, the <h3>Display me!</h3> part doesn't show
The render :partial => 'form' from the 'blah' action just renders the
and doesn't update the "update_me" <div> section. The WEBrick output is
follows: - - [12/Dec/2005:10:43:28 Eastern Standard Time] "GET
HTTP/1.1" 200 851

- -> /guesswhat - - [12/Dec/2005:10:43:28 Eastern Standard Time] "GET
HTTP/1.1" 200 0

- -> /favicon.ico - - [12/Dec/2005:10:43:32 Eastern Standard Time] "POST
/guesswhat/guess HTTP/1.1" 200 623

http://localhost:3000/guesswhat -> /guesswhat/guess

Notice the difference between the first and third actions:
- -> /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
and see what you encounter.

Thanks in advance,
D6c13e82448f753fde1a51d79e59d92c?d=identicon&s=25 stephen karsch (Guest)
on 2005-12-12 18:27
(Received via mailing list)
make sure you are including the javascript prototype library

<%= javascript_include_tag "prototype" %>

hope that helps!
Cb610750ee94ca103aef4b2dc7b1b768?d=identicon&s=25 Nick Stuart (Guest)
on 2005-12-12 18:28
(Received via mailing list)
First step, have you included the required java scripts on the page?
<%= javascript_include_tag :defaults %>

I read through the part and I dont think they mention the needed
includes (or at least its hard to spot when they do).
This topic is locked and can not be replied to.