Skip to content

Instantly share code, notes, and snippets.

@eduardopoleo
Created July 24, 2016 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardopoleo/9b664f5362feac04a55963bdaeaa3463 to your computer and use it in GitHub Desktop.
Save eduardopoleo/9b664f5362feac04a55963bdaeaa3463 to your computer and use it in GitHub Desktop.
#averages_controller.rb
class AveragesController < ApplicationController
#Uses the use_case flag to query for the correct type of averages
def all_salaries
@data = Average.where(use_case: "overall_salaries")
respond_to_block
end
def professors_only
@data = Average.where(use_case: "professors_only")
respond_to_block
end
def administrative_staff
@data = Average.where(use_case: "administrative_only")
respond_to_block
end
private
def respond_to_block
respond_to do |format|
format.json { render json: @data }
end
end
end
#average.rb
class Average < ActiveRecord::Base
# This is a rails magical thing that sets the structure of the JSON object that we are going to render
def serializable_hash(options = {})
{
university: university,
average_salary: average_salary
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment