Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Sortable Table Columns
======================

Expand Down Expand Up @@ -53,9 +52,17 @@ In a view, mark up sortable columns by using the <tt>sortable_column</tt> helper
<%= sortable_column "Price" %>

In controller action, fetch and use the order clause according to current state of sortable columns:


@@sortable_columns = %w(product price)
@@default_order = 'name'
def index
order = sortable_column_order

if @@sortable_columns.include? sortable_column_order
order = sortable_column_order
else
order = @@default_order
end

@records = Article.order(order) # Rails 3.
@records = Article.all(:order => order) # Rails 2.
end
Expand Down