Sha256: 201aa47371a05769dc3a211cf3af3cdd91a2ab248607e97cdcee8f0db2b588cf
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
# -*- encoding : utf-8 -*- require 'search/conditions/abstract' module RademadeAdmin module Search module Conditions class RelatedList < Abstract def base_condition(model) model_related_name = model.to_s.tableize.gsub('/', '_').to_sym @params[:parent].constantize.find(@params[:parent_id]).send(model_related_name) end protected def where where_conditions = Where.new(:and) @params.slice(*@origin_fields).each do |field, value| where_conditions.add(field, value) end where_conditions end def order field = @params[:sort] || default_order_field [{field => direction}] end def page @params[:page] || 1 end def per_page @params[:paginate] || 20 end private def default_order_field @origin_fields.include?('position') ? :position : :id end def direction if @params[:direction].present? @params[:direction].to_sym else :asc end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rademade_admin-0.0.3 | app/services/search/conditions/related_list.rb |
rademade_admin-0.0.2 | app/services/search/conditions/related_list.rb |