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<%= 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