jcraigk/phishin

View on GitHub
app/controllers/venues_controller.rb

Summary

Maintainability
A
30 mins
Test Coverage
class VenuesController < ApplicationController
  caches_action_params :index

  def index
    @venues = Venue.name_starting_with(char_param).order(order_by)
    render_xhr_without_layout
  end

  private

  def order_by
    params[:sort] = 'name' unless params[:sort].in?(%w[name performances])
    case params[:sort]
    when 'name' then { name: :asc }
    when 'performances' then { shows_count: :desc, name: :asc }
    end
  end
end