Forum: Ruby on Rails text_field_with_auto_complete (newbie question)

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.
316c03a99e8ed311e5462d94f085fc2e?d=identicon&s=25 John Ivanoff (Guest)
on 2006-05-17 23:15
(Received via mailing list)
I have the text_field_with_auto_complete woking on my user DB using
last_name. so looking for 'ivanoff' works great, but I can't find
'john'. Plus I like to have 'last_name, first_name' show up in the
dropdown.

what I can't figure out is how to concat first_name and last_name to
make a name and use that to look it.

working code
<%= text_field_with_auto_complete :user, :last_name %>

where do I concatinate first_name and last_name to make a name?

thanks
John
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-05-18 01:47
(Received via mailing list)
On Wed, 2006-05-17 at 16:12 -0500, John Ivanoff wrote:
>
> where do I concatinate first_name and last_name to make a name?
----
check the wiki and api for 'aggregations'

The topic is covered in Agile Web Development for Rails as well.

Craig
316c03a99e8ed311e5462d94f085fc2e?d=identicon&s=25 John Ivanoff (Guest)
on 2006-05-18 17:10
(Received via mailing list)
thanks,
I understand what that does but I couldn't get it to work.
it was looking for the 'name' column in the database but I followed
the examples in the book (changing the variable names where needed)
maybe my mapping isn't right.

I found something that will work although it's not what I really want
to do. http://demo.script.aculo.us/ajax/autocompleter_customized

using this I can only look at the last name but at least the fisrt
name is now displaying. (yes I'm cringing too) I'll get back to the
'aggregations' because I'd like to be able to look up by first name as
well as last name.

thanks.

john
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-05-18 17:33
(Received via mailing list)
On Thu, 2006-05-18 at 10:07 -0500, John Ivanoff wrote:
> name is now displaying. (yes I'm cringing too) I'll get back to the
> > > last_name. so looking for 'ivanoff' works great, but I can't find
> > ----
> > check the wiki and api for 'aggregations'
> >
> > The topic is covered in Agile Web Development for Rails as well.
> >
----
perhaps this will help...

controller code

  # Provides ajax auto complete list rather than using pop-up list
  def auto_complete_for_placement_clwholename
    auto_complete_responder_for_clients params[:placement][:clwholename]
  end

  private

  # Controller code for auto create
  def auto_complete_responder_for_clients(value)
    @clients = Client.find(:all,
    :conditions => ["LOWER(first_name||middle_initial||last_name)
LIKE ?",
      '%' + params[:placement][:clwholename].downcase + '%'],
    :order => 'last_name ASC',
    :limit => 8)
    render :partial => 'auto_cl'
  end

view code...
    <td><label for="client_clwholename">Client</label><br/>
        <%= text_field_with_auto_complete :placement, :clwholename, {} %
></td>

and my partial _auto_cl.rhtml
<ul class="placement">
<% for client in @clients do -%>
<li class="placement">
<div class="clwholename"><%=h client.clwholename %>-<%= client.id %
></div></li>
<% end -%>
</ul>

Craig

Craig
316c03a99e8ed311e5462d94f085fc2e?d=identicon&s=25 John Ivanoff (Guest)
on 2006-05-18 20:28
(Received via mailing list)
Where's mt staples "that was easy" button?

just one change.
from
:conditions => ["LOWER(first_name||middle_initial||last_name) LIKE ?",
to
:conditions => ["LOWER(Concat(last_name,  ', ', first_name)) LIKE ?",

mysql doesn't like || or  + to caoncatenate.

thanks.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-05-18 22:46
(Received via mailing list)
Glad it worked for you...it took me a while to figure out the || for
postgres

Craig
This topic is locked and can not be replied to.