Forum: Ruby on Rails Find collection where :name beings with a letter

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.
94cc3e46cfc5bc361e409e2e884ecfa4?d=identicon&s=25 Drew Olson (dfg59)
on 2007-02-19 16:53
All -

I want to find a collection of records where name begins with the same
letter as my_string. How would I do that? Something along the lines of:

Records.find(:all,:conditions=>{:name=>my_string[0].chr})

Thanks,
Drew
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-19 17:22
(Received via mailing list)
# find all records where name starts with the first char of my_string
find(:all, :conditions => ["name_column LIKE ?", "#{my_string.first}%"])
This topic is locked and can not be replied to.