How to DRY up my code

Is there a good book that really shows you how to DRY up your code?

Because I don’t want to repeat my code all over again for all the 26
alphabetical letters.

Here is my code that I use for 1 letter for the controller Client:

def index
@clients = @clients = Client.find :all, :conditions => “firstname like
‘M%’”, :order => “firstname ASC”
end

Then on my View index.rhtml I have this:

Listing Clients with First Name starting with M <% @clients.each do |client| %> <%end%>
<%= link_to client.firstname, :action => 'show', :id => client.id %>

And after the tag I would like to have a link like this:
<%= link_to ‘N’, :action => index :letter or something to represent my
letter I wan to use%>

So in my controller Client I would have:

def index
@clients = @clients = Client.find :all, :conditions => “firstname like
‘?’”, :order => “firstname ASC”
end

Thanks

<%= link_to “N”, :action => “index”, :letter => “N” %>

controller:

def index
@clients = Client.find :all, :conditions => [ “firstname like ‘?%’”,
params[:letter] ], :order => “firstname ASC”
end

Jason

Jason R. wrote:

<%= link_to “N”, :action => “index”, :letter => “N” %>

controller:

def index
@clients = Client.find :all, :conditions => [ “firstname like ‘?%’”,
params[:letter] ], :order => “firstname ASC”
end

Jason
Ok i’ve tried that, but when I click on my link it gives me this error:

error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ‘M’%’) ORDER BY
firstname ASC’ at line 1: SELECT * FROM clients WHERE (firstname like
‘‘M’%’

Thanks

Oh its ok, I fixed it, thanks