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

**URL:** <https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060>\
**Category:** Rails\
**Created:** [January 10, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060 "2006-01-10T16:29:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 10, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/1 "2006-01-10T16:29:00Z")

</div>

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/](http://number9.hellooperator.net/)

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 10, 2006, 4:40pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/2 "2006-01-10T16:40:59Z")

</div>

Could you post the code you’re using?

render :partial =\> ‘yourpartial’

shouldn’t include a layout…

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 10, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/3 "2006-01-10T21:47:15Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Rasputin :: Jack of All Trades - Master of Nuns  
[http://number9.hellooperator.net/](http://number9.hellooperator.net/)

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 10, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/4 "2006-01-10T22:05:38Z")

</div>

Please post your code if this:

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

doesn’t help.

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 11, 2006, 8:21am UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/5 "2006-01-11T08:21:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 11, 2006, 8:42am UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/6 "2006-01-11T08:42:46Z")

</div>

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

> **[Pragmatic Bookshelf: By Developers, For Developers](https://pragprog.com)**
>
> We improve the lives of professional developers. We create timely, practical books on classic and cutting-edge topics to help you learn and practice your craft, and accelerate your career. Come learn with us.

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)  
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.  
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-  
> > Dan S.  
> > Technology Visionary - Technology Assessment - Documentation  
> > “Looking at technology from every angle”  
> > [http://www.eclecticity.com](http://www.eclecticity.com)

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 11, 2006, 2:09pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/7 "2006-01-11T14:09:16Z")

</div>

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:

- Universal Troubleshooting Process courseware
- Troubleshooting Techniques of the Successful Technologist
- Rapid Learning: Secret Weapon of the Successful Technologist  
Webmaster
- [Troubleshooters.Com](http://Troubleshooters.Com)
- [http://www.troubleshooters.com](http://www.troubleshooters.com)

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 11, 2006, 3:32pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/8 "2006-01-11T15:32:46Z")

</div>

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

[http://files.hellooperator.net/aj.tgz](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > b) some interaction between ajax and partials  
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Rasputin :: Jack of All Trades - Master of Nuns  
[http://number9.hellooperator.net/](http://number9.hellooperator.net/)

---

<div class="post-metadata">

**Author:** ![dishkuvek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ebca7d/32.png) [@dishkuvek](https://www.ruby-forum.com/u/dishkuvek)\
**Post date:** [January 11, 2006, 5:39pm UTC](https://www.ruby-forum.com/t/first-ajax-demo-in-rails-book-does-it-work-for-anyone/52060/9 "2006-01-11T17:39:22Z")

</div>

On 11/01/06, Steve L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://number9.hellooperator.net/)
