8
9
10
11
12
13
14
15
16
17
|
# File 'app/controllers/testimonials/api/testimonials_controller.rb', line 8
def index
scope = Testimonial.publishable.featured_first
scope = scope.where(featured: true) if params[:featured].present?
scope = scope.where(kind: params[:kind]) if Testimonial::KINDS.include?(params[:kind])
scope = scope.where(rating: params[:min_rating].to_i..) if params[:min_rating].present?
limit = params[:limit].to_i.clamp(1, MAX_LIMIT)
limit = MAX_LIMIT if params[:limit].blank?
render json: { testimonials: scope.limit(limit).map { |t| serialize(t) } }
end
|