John Ivanoff
2006-May-17 21:12 UTC
[Rails] text_field_with_auto_complete (newbie question)
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
On Wed, 2006-05-17 at 16:12 -0500, John Ivanoff wrote:> 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?---- check the wiki and api for ''aggregations'' The topic is covered in Agile Web Development for Rails as well. Craig
John Ivanoff
2006-May-18 15:07 UTC
[Rails] text_field_with_auto_complete (newbie question)
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 On 5/17/06, Craig White <craigwhite@azapple.com> wrote:> On Wed, 2006-05-17 at 16:12 -0500, John Ivanoff wrote: > > 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? > ---- > check the wiki and api for ''aggregations'' > > The topic is covered in Agile Web Development for Rails as well. > > Craig > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Thu, 2006-05-18 at 10:07 -0500, John Ivanoff wrote:> 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 > > On 5/17/06, Craig White <craigwhite@azapple.com> wrote: > > On Wed, 2006-05-17 at 16:12 -0500, John Ivanoff wrote: > > > 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? > > ---- > > 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
John Ivanoff
2006-May-18 18:27 UTC
[Rails] text_field_with_auto_complete (newbie question)
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. On 5/18/06, Craig White <craigwhite@azapple.com> wrote:> On Thu, 2006-05-18 at 10:07 -0500, John Ivanoff wrote: > > 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 > > > > On 5/17/06, Craig White <craigwhite@azapple.com> wrote: > > > On Wed, 2006-05-17 at 16:12 -0500, John Ivanoff wrote: > > > > 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? > > > ---- > > > 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 > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Glad it worked for you...it took me a while to figure out the || for postgres Craig On Thu, 2006-05-18 at 13:27 -0500, John Ivanoff wrote:> 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. > > > On 5/18/06, Craig White <craigwhite@azapple.com> wrote: > > On Thu, 2006-05-18 at 10:07 -0500, John Ivanoff wrote: > > > 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 > > > > > > On 5/17/06, Craig White <craigwhite@azapple.com> wrote: > > > > On Wed, 2006-05-17 at 16:12 -0500, John Ivanoff wrote: > > > > > 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? > > > > ---- > > > > 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 > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails