Hi Is it possible to use the autocomplete plugin to search using a keyword on more than one field of a model? How can I do that? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
If I understand well the question the answer should be yes. If what you mean is if it is possible to use one field on a page to find data in more than one column in the table it should be possible the only thing you would need is to query the table by the columns you desire to query on. On May 10, 7:23 pm, Mlle <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi > > Is it possible to use the autocomplete plugin to search using a > keyword on more than one field of a model? How can I do that?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 10, 2011, at 7:23 PM, Mlle wrote:> Hi > > Is it possible to use the autocomplete plugin to search using a > keyword on more than one field of a model? How can I do that?When you use autocompletion, you define a field to watch, and an endpoint to query against. Whatever query conditions you put in the method that "answers" that endpoint will be the results that appear in the autocompleter''s list. So if you had generated: new Ajax.Autocompleter(''person'',''/people/lookup'',{}); Then in Person#lookup you would be looking for Person.all(:conditions => [''first_name LIKE ? OR last_name LIKE ?''],"#{params[:value]}%","#{params[:value]}%"]) Crude example, but you get the idea... Walter> > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for your comments. I understand what you''re saying but I guess my question had more to do with the population of the actual list, not the database query. If you use the autocomplete plugin, the list that populates under the input box has to be a certain field of a certain model. For example, when you call this helper: model_auto_completer_result(@inventories, :inventory_id ) the inventory_id is displayed for each inventory item matching the query. I''d like to search on two fields in the inventories table and display whichever field matched in the autocomplete list. On May 11, 10:05 am, Walter Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> On May 10, 2011, at 7:23 PM, Mlle wrote: > > > Hi > > > Is it possible to use the autocomplete plugin to search using a > > keyword on more than one field of a model? How can I do that? > > When you use autocompletion, you define a field to watch, and an > endpoint to query against. Whatever query conditions you put in the > method that "answers" that endpoint will be the results that appear in > the autocompleter''s list. > > So if you had generated: > > new Ajax.Autocompleter(''person'',''/people/lookup'',{}); > > Then in Person#lookup you would be looking for > > Person.all(:conditions => [''first_name LIKE ? OR last_name > LIKE ?''],"#{params[:value]}%","#{params[:value]}%"]) > > Crude example, but you get the idea... > > Walter > > > > > > > > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails- > > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > . > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en > > .-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 11, 2011, at 11:27 AM, Mlle wrote:> Thanks for your comments. I understand what you''re saying but I guess > my question had more to do with the population of the actual list, not > the database query. If you use the autocomplete plugin, the list that > populates under the input box has to be a certain field of a certain > model. For example, when you call this helper: > > model_auto_completer_result(@inventories, :inventory_id ) > > the inventory_id is displayed for each inventory item matching the > query. I''d like to search on two fields in the inventories table and > display whichever field matched in the autocomplete list.Back up to the line where you define @inventories. That''s where you would make the filter broad enough to include hits on more than one field. Walter> > > > On May 11, 10:05 am, Walter Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> On May 10, 2011, at 7:23 PM, Mlle wrote: >> >>> Hi >> >>> Is it possible to use the autocomplete plugin to search using a >>> keyword on more than one field of a model? How can I do that? >> >> When you use autocompletion, you define a field to watch, and an >> endpoint to query against. Whatever query conditions you put in the >> method that "answers" that endpoint will be the results that appear >> in >> the autocompleter''s list. >> >> So if you had generated: >> >> new Ajax.Autocompleter(''person'',''/people/lookup'',{}); >> >> Then in Person#lookup you would be looking for >> >> Person.all(:conditions => [''first_name LIKE ? OR last_name >> LIKE ?''],"#{params[:value]}%","#{params[:value]}%"]) >> >> Crude example, but you get the idea... >> >> Walter >> >> >> >> >> >> >> >> >> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails- >>> talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>> . >>> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en >>> . > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.