Forum: Ruby on Rails Ajax - from there to here

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.
Craig W. (Guest)
on 2006-02-27 09:21
(Received via mailing list)
Trying to use Amy Hoy's ajaxariffic auto_complete methodology and I am
getting really close to the end.

This is fairly complicated but I will simplify as best I can.

My view code is simple...

  <%= text_field_with_auto_complete 'client', 'wholename' %>

# wholename is not a column in 'clients' but rather represents an
aggregation of 3 fields...first_name, middle_initial, last_name

my controller code does the necessary part to display the
'auto_complete' listing...

  def auto_complete_for_client_wholename
    @clients = Client.find(:all,
    :conditions => ["LOWER(first_name||middle_initial||last_name)
      LIKE ?",
      '%' + params[:client][:wholename].downcase + '%'],
    :order => 'last_name ASC',
    :limit => 8)
    render :partial => 'cookies'

and my cookies partial looks like this...

<% for client in @clients do -%>
<li class="clients"><%=h client.clwholename %></li>
<% end -%>

# clwholename is the actual aggregation in client.rb

so far so good...when I type a letter or two, the auto_complete list
shows and I can select a name from the list.

But then my problem starts. I can't **easily** 'find' based on the I would like it to handle it more like a select list
where the 'ID' invisibly accompanies the auto_complete text and thus
selecting an auto_complete item will give me the ID so I don't have to
then turn around and search for it.

How do I send that with the 'cookies' partial?

Eric G. (Guest)
on 2006-02-27 09:45
(Received via mailing list)
Hi Craig,
Not positive what you are looking for here, but here goes.
You are already selecting :all so in your view if you want the id all
should have to do is :

<% for client in @clients do -%>
<li class="clients"><%=link_to client.clwholename, :action='show',
:id=>client %></li><% end -%>

If you want to link to it that is. You can grab just the id with client

If you want to link via ajax with it then you can use link_to_remote

Not sure if I read your post right, but if I did I hope this helps.

Eric G.
Craig W. (Guest)
on 2006-02-27 17:53
(Received via mailing list)
The _cookies.rhtml (what I called cookies partial) didn't directly write
to screen but actually sent code back to ajax view. Thus I couldn't use
new render commands within the code.

A select list in 'source' view looks something like this...

<input id="client.clwholename" name="client[clwholename]">
  <option value="">Select a Name</option>
  <option value="2">George Washington</option>
  <option value="3">John Adams</optoin

my cookies partial again is...
<% for client in @clients do -%>
<li class="clients"><%=h client.clwholename %></li>
<% end -%>

and I gather that I need to pass a 'value'
so if I change the middle line to...

<li class="clients"><%=h client.clwholename %><div class="value"><%=h %></div></li>

but the 'value' isn't hidden, it's displayed after the name and
selecting a name also writes the 'value' which is sort of a mess.

I guess the issue of using auto_complete is to make it an ersatz select
list and a select list would show you a list of values from a column
that would pass the record id to the code and that is what I am trying
to achieve with the auto_complete.

I hope this is clearer.


> </ul>
> Eric G.
This topic is locked and can not be replied to.