Forum: Ruby on Rails Ajax - from there to here

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.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-27 08: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'
  end

and my cookies partial looks like this...

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

# 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
aggregate...so 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?

Craig
Ac1da5d66d51a1c3b843221032247b30?d=identicon&s=25 Eric Goodwin (Guest)
on 2006-02-27 08: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
you
should have to do is :

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

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

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.

Cheers,
Eric Goodwin
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-27 16: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
</input>

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

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
client.id %></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.

thanks

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