I just noticed that the auto_complete_result method in the auto_complete plugin calls the field (as opposed to the method) to generate the result list. Here''s what it is: def auto_complete_result(entries, field, phrase = nil) return unless entries items = entries.map { |entry| content_tag("li", phrase ? highlight(entry[field], phrase) : h(entry[field)) } content_tag("ul", items.uniq) end I''ve changed it to (and what I think it should to be) : def auto_complete_result(entries, method, phrase = nil) return unless entries items = entries.map { |entry| content_tag("li", phrase ? highlight(entry.send(method), phrase) : h(entry.send(method))) } content_tag("ul", items.uniq) end What is the rationale for using the field rather than the method? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Thanks for the tip! I totally agree with you that the method makes more sense (and allows for more flexibility) and I have implemented the same change in my application based on your code. My person model has first_name and last_name fields so to make a list of person results, I would have to choose between displaying either first name or last name in the auto-complete result list, which isn''t acceptable. So I created a method full_name that combines the two fields and after implementing your changes, I am able to populate the result list using the full_name method call instead of one of the fields. tekwiz wrote:> I just noticed that the auto_complete_result method in the > auto_complete plugin calls the field (as opposed to the method) to > generate the result list. > > Here''s what it is: > > def auto_complete_result(entries, field, phrase = nil) > return unless entries > items = entries.map { |entry| content_tag("li", phrase ? > highlight(entry[field], phrase) : h(entry[field)) } > content_tag("ul", items.uniq) > end > > I''ve changed it to (and what I think it should to be) : > > def auto_complete_result(entries, method, phrase = nil) > return unless entries > items = entries.map { |entry| content_tag("li", phrase ? > highlight(entry.send(method), phrase) : h(entry.send(method))) } > content_tag("ul", items.uniq) > end > > What is the rationale for using the field rather than the method?-- Posted via http://www.ruby-forum.com/.