Displaying only titles that starts with a defined caracter

Hi,

I would like to know how to display only titles of products that starts
with a defined letter (ie: titles that begin with A)

Here is the method that I use to place all titles in alphabetical order:

class Livre < ActiveRecord::Base
validates_presence_of :titre;

def self.alpha
    find(   :all,
            :order  => "titre ASC"
            )
end

end

Any ideas ?

Thank you!

What about

def self.alpha( letter = nil )
find :all, :order => “titre ASC”, :conditions => “titre LIKE
‘#{letter}%’”
end

That is assuming your using mysql

On 3/23/06, weirdmonkey [email protected] wrote:

def self.alpha
    find(   :all,
            :order  => "titre ASC"
            )
end

end

Any ideas ?

Thank you!

How about?

class Livre < ActiveRecord::Base
def self.beginning_with(prefix)
clause = prefix + ‘%’
find(:all, :conditions => [“titre like ?”, clause], :order => “titre
ASC”)
end
end

Livre.beginning_with(‘A’)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs