Module: KirguduBase::Models::Sorting::InstanceMethods

Defined in:
app/helpers/kirgudu_base/models/sorting.rb

Instance Method Summary collapse

Instance Method Details

#sanitize_sort_by(sort_by) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/kirgudu_base/models/sorting.rb', line 67

def sanitize_sort_by(sort_by)
	sanitized_value = nil

	if self.class.respond_to?(:allowed_fields_to_sort)
		unless sort_by.nil?
			sort_by = sort_by.to_s
			unless  sort_by.empty?
				fields_to_sort = self.allowed_fields_to_sort
				fields_to_sort.each do |fts|
					if fts.downcase == sort_by
						if self.attributes.keys.include?(sort_by)
							sanitized_value = sort_by.downcase
							break
						end
					end
				end
			end
		end
	end
	unless sanitized_value
		if self.class.respond_to?(:default_sort_field)
			if self.attributes.keys.include?(:default_sort_field)
				sanitized_value = self.default_sort_field
			end
		end
	end

	sanitized_value || "id"
end