Forum: Ruby on Rails Structuring a find that looks at the first letter of a field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C65fbc91799a72e3363a8031ea0c41e5?d=identicon&s=25 Robert Scott (rscott239)
on 2009-03-21 09:01
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.
36ed63ef68c172f148c491418395d0b5?d=identicon&s=25 rubyguy@ymail.com (Guest)
on 2009-03-21 09:28
(Received via mailing list)
On 21 Mar., 09:01, Robert Scott <rails-mailing-l...@andreas-s.net>
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
This topic is locked and can not be replied to.