Forum: Ruby on Rails first ajax demo in Rails book - does it work for anyone?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A52b0e1c5d982f2512a03c5dbfd033d6?d=identicon&s=25 Dick Davies (Guest)
on 2006-01-10 16:29
(Received via mailing list)
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/
71f1b6b2c3fd9af2e8c52618fb91caa6?d=identicon&s=25 Jules Jacobs (jules)
on 2006-01-10 16:40
Could you post the code you're using?

render :partial => 'yourpartial'

shouldn't include a layout...
A52b0e1c5d982f2512a03c5dbfd033d6?d=identicon&s=25 Dick Davies (Guest)
on 2006-01-10 21:47
(Received via mailing list)
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 Jacobs <julesjacobs@gmail.com> wrote:
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/
71f1b6b2c3fd9af2e8c52618fb91caa6?d=identicon&s=25 Jules Jacobs (jules)
on 2006-01-10 22:05
Please post your code if this:

render :partial => 'form', :layout => false

doesn't help.
5d06917e13b29bcff1c1609492c06873?d=identicon&s=25 Dave Thomas (Guest)
on 2006-01-11 08:21
(Received via mailing list)
On Jan 10, 2006, at 9:27, Dick Davies 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
205bc8d44e9bc5c68d77dd412abcb3ce?d=identicon&s=25 Dan Shafer (Guest)
on 2006-01-11 08:42
(Received via mailing list)
that code (p. 392 in the printed version if I'm following you) is
noted as erroneous at the book's Web site:

http://books.pragprog.com/titles/rails/errata

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 Davies wrote:

> On 10/01/06, Jules Jacobs <julesjacobs@gmail.com> wrote:
>> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
Dan Shafer
Technology Visionary - Technology Assessment - Documentation
"Looking at technology from every angle"
http://www.eclecticity.com
C9af522fc39d5de90f21119543c2b9ab?d=identicon&s=25 Steve Litt (Guest)
on 2006-01-11 14:09
(Received via mailing list)
On Wednesday 11 January 2006 02:18 am, Dave Thomas 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 Litt
Author:
   * Universal Troubleshooting Process courseware
   * Troubleshooting Techniques of the Successful Technologist
   * Rapid Learning: Secret Weapon of the Successful Technologist
Webmaster
   * Troubleshooters.Com
   * http://www.troubleshooters.com
A52b0e1c5d982f2512a03c5dbfd033d6?d=identicon&s=25 Dick Davies (Guest)
on 2006-01-11 15:32
(Received via mailing list)
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 %>
  <p>don't think '<%= h(@guess) %>' is right....</p>
<% end %>

<%= form_remote_tag(:update => 'update_div',
                    :url    => { :action => :guess }
                   ) %>
  <label for='guess'>thick as 2 short....?</label>
  <%= text_field_tag :guess %>
  <%= submit_tag 'do the ajax thing' %>
<%= end_form_tag %>

sisred@planb:~/Desktop/aj$ cat app/views/ajax_test/guess.rhtml
<h1>AjaxTest#guess</h1>
<p>Find me in app/views/ajax_test/guess.rhtml</p>
sisred@planb:~/Desktop/aj$ cat app/views/ajax_test/_form.rhtml
<% if @guess # if it was right, we wouldn't be rendering this partial %>
  <p>don't think '<%= h(@guess) %>' is right....</p>
<% end %>

<%= form_remote_tag(:update => 'update_div',
                    :url    => { :action => :guess }
                   ) %>
  <label for='guess'>thick as 2 short....?</label>
  <%= text_field_tag :guess %>
  <%= submit_tag 'do the ajax thing' %>
<%= end_form_tag %>

sisred@planb:~/Desktop/aj$ cat app/views/ajax_test/index.rhtml
<h1>have a guess</h1>
<div id="update_div" style="background.color:#ddd">
  <%= render(:partial => 'form',
             :layout => false ) %>
</div>

</p>

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 Thomas <Dave@pragprog.com> wrote:
> > b) some interaction between ajax and partials
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/
A52b0e1c5d982f2512a03c5dbfd033d6?d=identicon&s=25 Dick Davies (Guest)
on 2006-01-11 17:39
(Received via mailing list)
On 11/01/06, Steve Litt <slitt@troubleshooters.com> 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/
This topic is locked and can not be replied to.