Created
July 24, 2016 17:33
-
-
Save eduardopoleo/9b664f5362feac04a55963bdaeaa3463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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