Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Forked from anonymous/gist:3417328
Created August 21, 2012 17:06
Show Gist options
  • Save bil-bas/3417354 to your computer and use it in GitHub Desktop.
Save bil-bas/3417354 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 self.class::SORT_MODEL.inspect
self.class::SORT_MODEL.column_names.include?(params[:sort]) ? params[:sort] : self.class::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 self.class::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