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…
<% for client in @clients do -%>
- <%=h client.clwholename %>
<% 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
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
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 :
<% for client in @clients do -%>
- <%=link_to client.clwholename, :action='show',
:id=>client %>
<% end -%>
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 G.
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…
Select a Name
George Washington
John Adams</optoin
my cookies partial again is…
<% for client in @clients do -%>
- <%=h client.clwholename %>
<% end -%>
and I gather that I need to pass a ‘value’
so if I change the middle line to…
<%=h client.clwholename %><%=h
client.id %>
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
Eric G.