AJAX in Ruby on Rails

C

Charlie Squires

I'm having some trouble getting AJAX working properly for me in Rails. I've
tried the example in "Agile Web Development with Rails" on page 391 using
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 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:
<h3>Display me!</h3>
<div id="update_me">
<%= render:)partial => 'form') %>
</div>

_form.rhtml:
<% 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 again.
The render :partial => 'form' from the 'blah' action just renders the form
and doesn't update the "update_me" <div> 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 -> /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 yourself
and see what you encounter.

Thanks in advance,
Charlie
 
C

Charlie Squires

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top