Robert Scott
2009-Mar-21 08:01 UTC
Structuring a find that looks at the first letter of a field
I guess the subject is fairly self-explanatory. I''m pretty new to RoR, but I''d like to learn how to structure a find that looks at the first character of a field, say firstname, to find those that match a parameter passed in to the controller. Hopefully it''s not too difficult. :/ Thanks in advance. -- 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 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 -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-21 08:27 UTC
Re: Structuring a find that looks at the first letter of a field
On 21 Mar., 09:01, Robert Scott <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I guess the subject is fairly self-explanatory. I''m pretty new to RoR, > but I''d like to learn how to structure a find that looks at the first > character of a field, say firstname, to find those that match a > parameter passed in to the controller. > > Hopefully it''s not too difficult. :/ > Thanks in advance.@person = Person,find(:all, :conditions => ["firstname LIKE ?%", params [:letter]] The question mark is replaced with params[:letter]. There is plenty of material on the LIKE keyword on the internet, so if you don''t know what it does, go ahead and do some research. -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---