Skip to content

Instantly share code, notes, and snippets.

View Breefield's full-sized avatar

Bree Hoffman Breefield

View GitHub Profile
# 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
Location.near('San Francisco', 50).filtered_by(:event).where('events.price <= ?', 20)
# 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'
def index
@animals = Animal.all
render json: @animals
end
def index
@animals = Animal.all
render json: @animals
end
def show
render json: @animal
end
def index
@animals = Animal.all
respond_to do |f|
f.html {}
f.json { render json: @animals }
end
end
class AnimalSerializer < ActiveModel::Serializer
embed :ids, include: true
attributes :id, :kind, :classification
has_many :waterholes
end
{
"animal": {
"id": 1,
"kind": "Lion",
"waterhole_ids": [1, 2]
},
"waterholes": [
{ "id": 1, "name": "lots of water here" },
{ "id": 2, "name": "so much h2o"}
],
{
"animal": {
"id": 1,
"kind": "Lion",
"waterhole_ids": [1, 2]
},
"waterholes": [
{ "id": 1, "name": "lots of water here" },
{ "id": 2, "name": "so much h2o"}
],
<div class="big-number">
<h1>{{ options.speed }}</h1>
{{#if options.speed > 500}}
<p>Wow that's really fast
{{/if}}
</div>
<style type="text/css">
#plugin-{{id}} {