Skip to content

Instantly share code, notes, and snippets.

@julesfern
Created May 22, 2009 14:14
Show Gist options
  • Select an option

  • Save julesfern/116148 to your computer and use it in GitHub Desktop.

Select an option

Save julesfern/116148 to your computer and use it in GitHub Desktop.
# Model
class Donor
#.... a bunch of stuff
def self.find_for_params(params={})
find :all, :order=>sort_statement_for_param(params[:sort])
end
def self.sort_statement_for_param(sort)
case sort
when 'first_name'
"first"
else
"created_on"
end
end
end
# Controller
class DonorController
def index
@donors = Donor.find_for_params(params)
end
end
# View
<table>
<tr>
<th><%= link_to "First name", :sort=>"first_name" %></th>
<th><%= link_to "First name", :sort=>"last_name" %></th>
</tr>
<tr>
content...
</tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment