Skip to content

Instantly share code, notes, and snippets.

Created August 21, 2012 17:03
Show Gist options
  • Save anonymous/3417328 to your computer and use it in GitHub Desktop.
Save anonymous/3417328 to your computer and use it in GitHub Desktop.
class RawDataController < ApplicationController
helper_method :sort_column, :sort_direction
def index
end
protected
def sort_column
logger.debug @sort_model.inspect
@sort_model.column_names.include?(params[:sort]) ? params[:sort] : @sort_default_col
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
end
end
class DevicesController < RawDataController
@sort_model = Device
@sort_default_col = 'blah'
def index
logger.debug @sort_model.inspect
@devices = Device.search(params[:search]).order(sort_column + " " + sort_direction).paginate(:per_page => 40, :page => params[:page])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment