Sha256: 18152b23210f8ed5a9498692c9502d2208dcbe84c5f418ebc0ae8958b2b35459
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
module CustomizeAdmin class BaseController < ApplicationController inherit_resources helper_method :sort_column, :sort_direction, :string_filter before_filter :authenticate_admin_user! SEARCH_QUERY = "name LIKE ?" # defaults :route_prefix => 'admin' protected def collection collection = search(params[:search]).order( sort_column + " " + sort_direction ).paginate(:per_page => CustomizeAdmin.per_page, :page => params[:page]) end def sort_column sort_params = params[:sort].to_s.downcase end_of_association_chain.column_names.include?(sort_params) ? sort_params : "id" end def sort_direction %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc" end def string_filter t=[] end_of_association_chain.columns.each do |m| m.type == :string ? t << m.name : "" end t end def search( s ) if s end_of_association_chain.where( "#{SEARCH_QUERY} ", "%#{s}%" ) else end_of_association_chain end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
customize_admin-0.0.13 | app/controllers/customize_admin/base_controller.rb |
customize_admin-0.0.12 | app/controllers/customize_admin/base_controller.rb |