Tim,
I really appreciate the time and thoughtfulness you put in your reply.
To clarify further from my original question, building from your
example.
contacts = [{:first_name=>'tim', :last_name=>'rand', :id =
1},{:first_name=>'jim', :last_name=>'band', :id =>
2},{:first_name=>'him', :last_name=>'crand', :id => 3}]
Using a search form, the user will submit a string, looking for a
particular contact in the array. Unfortunately, this might be just "tim"
or "rand" or "tim rand". If a match is found in the array, I need to
return the id number associated with the match.
Now, if I was accessing the information from a database table directly
instead of an array, something like this would probably suffice.
@contacts = Contact.find(:all, :conditions => [ 'LOWER(lastname) LIKE ?
OR LOWER(firstname) LIKE ?', '%' + value.downcase + '%','%' +
value.downcase + '%'])
Unfortunately, I'm not sure how to build the equivalent query for an
existing array. Sort_by helps, but I haven't found a way to allow it to
search both :first_name and :last_name - only one at a time.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---