You cant to add a model and a controller for each letter fo the alphabet? That's definately not DRY at all.... You should manage every letter in the same controller, and with the same model: - ClientController - Client (Model) #Controller: class ClientController < ActionController::Base
def index if params[:letter] cond = params[:letter] + "%" @letter = params[:letter] @clients = Client.find :all, :conditions => ["name like ?", cond], :order => "clients.name ASC" else @client = Clients.find :all, :order => "clients.name ASC" end end end
#Model: class client ActiveRecord::Base ...model logic... none nessessary for your example... end
#view: index.rhtml <html> <head> <%if @letter %> <title>Listing Clients with First Name starting with <%= @letter %></title> <% else %> <title>Listing all Clients</title> <% end %> </head> <body> <h1>Names By :</h1> <table> <% @clients.each do |client| %> <tr> <td><%= link_to client.firstname, :action => 'show', :id => client.id %></td> </tr> <%end%> </table> <%= link_to "All Names with N", {:action => index, :letter => "N" } -%> <%= link_to "All Names with O", {:action => index, :letter => "O" } -%> .... .... </body> </html>
Of Course i would use a dropdown to select the letter instead of link_to's, and do the layout differently, but for an example it should suffice.