This file contains hidden or 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
# Type is a :symbol of the model which you want to filter by | |
def self.filtered_by type | |
belongs_to type, :foreign_key => :located_id, :foreign_type => type.to_s.capitalize | |
where(:located_type => type.to_s.capitalize).joins(type).includes(:located) | |
end |
This file contains hidden or 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
Location.near('San Francisco', 50).filtered_by(:event).where('events.price <= ?', 20) |
This file contains hidden or 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
# This file is copied to spec/ when you run 'rails generate rspec:install' | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require "codeclimate-test-reporter" | |
CodeClimate::TestReporter.start | |
require 'rspec/rails' | |
require 'rspec/autorun' |
This file contains hidden or 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
def index | |
@animals = Animal.all | |
render json: @animals | |
end |
This file contains hidden or 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
def index | |
@animals = Animal.all | |
render json: @animals | |
end | |
def show | |
render json: @animal | |
end |
This file contains hidden or 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
def index | |
@animals = Animal.all | |
respond_to do |f| | |
f.html {} | |
f.json { render json: @animals } | |
end | |
end |
This file contains hidden or 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
class AnimalSerializer < ActiveModel::Serializer | |
embed :ids, include: true | |
attributes :id, :kind, :classification | |
has_many :waterholes | |
end |
This file contains hidden or 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
{ | |
"animal": { | |
"id": 1, | |
"kind": "Lion", | |
"waterhole_ids": [1, 2] | |
}, | |
"waterholes": [ | |
{ "id": 1, "name": "lots of water here" }, | |
{ "id": 2, "name": "so much h2o"} | |
], |
This file contains hidden or 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
{ | |
"animal": { | |
"id": 1, | |
"kind": "Lion", | |
"waterhole_ids": [1, 2] | |
}, | |
"waterholes": [ | |
{ "id": 1, "name": "lots of water here" }, | |
{ "id": 2, "name": "so much h2o"} | |
], |