First ajax demo in Rails book - does it work for anyone?

Just tried the first AJAX example in the rails book (p.391-392, the
‘word guessing’ thing), and the AJAX partial used seems to render as a
full page.

I’m not sure whether it’s

a) a partial bug
b) some interaction between ajax and partials
c) a change since the book came out
or
d) pilot error

I’ve checked the errata pages and it’s flagged up as b0rked there too
(on windows; I’m on ubuntu breezy with rails v1.0).

gmane drew a blank on the list archives, can anyone confirm/deny whether
this
worked for them?


Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/

Could you post the code you’re using?

render :partial => ‘yourpartial’

shouldn’t include a layout…

Thanks Jules, but it’s really just the code from the book
(unless I fat-fingered something). It does’nt use a layout,
just a partial.

Essentially the URL updates to point to the action that
form_remote_tag is calling via AJAX, which I don’t think it
should.

I can post code if this is ringing no bells at all…

On 10/01/06, Jules J. [email protected] wrote:

[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/

Please post your code if this:

render :partial => ‘form’, :layout => false

doesn’t help.

On Jan 10, 2006, at 9:27, Dick D. wrote:

d) pilot error
I’ll be looking at these incompatibilities over the coming months:
I’m guessing that adding :layout => false will fix it.

Dave

that code (p. 392 in the printed version if I’m following you) is
noted as erroneous at the book’s Web site:

Not sure if the comment following that one will help you because I
didn’t see your original post on this thread.

On Jan 10, 2006, at 12:44 PM, Dick D. wrote:

On 10/01/06, Jules J. [email protected] wrote:

[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Dan S.
Technology Visionary - Technology Assessment - Documentation
“Looking at technology from every angle”
http://www.eclecticity.com

On Wednesday 11 January 2006 02:18 am, Dave T. wrote:

or
d) pilot error

I’ll be looking at these incompatibilities over the coming months:
I’m guessing that adding :layout => false will fix it.

On my .pdf version of the book, your book has:

render(:layout => false)

SteveT

Steve L.
Author:

Nope, still b0rked - here’s all the source
(and there’s a tarred up app directory at

http://files.hellooperator.net/aj.tgz

)

Thanks for everyone’s suggestions so far, and apologies in advance
for when it turns out to be a typo…


sisred@planb:~/Desktop/aj$ cat app/views/ajax_test/_form.rhtml
<% if @guess %>

don't think '<%= h(@guess) %>' is right....

<% end %>

<%= form_remote_tag(:update => ‘update_div’,
:url => { :action => :guess }
) %>
thick as 2 short…?
<%= text_field_tag :guess %>
<%= submit_tag ‘do the ajax thing’ %>
<%= end_form_tag %>

sisred@planb:~/Desktop/aj$ cat app/views/ajax_test/guess.rhtml

AjaxTest#guess

Find me in app/views/ajax_test/guess.rhtml

sisred@planb:~/Desktop/aj$ cat app/views/ajax_test/_form.rhtml <% if @guess # if it was right, we wouldn't be rendering this partial %>

don't think '<%= h(@guess) %>' is right....

<% end %>

<%= form_remote_tag(:update => ‘update_div’,
:url => { :action => :guess }
) %>
thick as 2 short…?
<%= text_field_tag :guess %>
<%= submit_tag ‘do the ajax thing’ %>
<%= end_form_tag %>

sisred@planb:~/Desktop/aj$ cat app/views/ajax_test/index.rhtml

have a guess

<%= render(:partial => 'form', :layout => false ) %>

sisred@planb:~/Desktop/aj$ cat app/controllers/ajax_test_controller.rb
class AjaxTestController < ApplicationController

def index
end

def guess
@guess = params[:guess] || ‘’
if @guess.strip.match /^planks$/i
render(:text => ‘right on commander’)
else
render(:partial => ‘form’, :layout => false)
end
end
end


On 11/01/06, Dave T. [email protected] wrote:

b) some interaction between ajax and partials
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/

On 11/01/06, Steve L. [email protected] wrote:

On my .pdf version of the book, your book has:

render(:layout => false)

To clarify, I’m talking about the deadtree version, and adding
the :layout => false key to the options hash does’nt appear
to make any difference.


Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/