Skip to content

Instantly share code, notes, and snippets.

View BenMorganIO's full-sized avatar
😀
Why is this here?

Ben A. Morgan BenMorganIO

😀
Why is this here?
View GitHub Profile
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember HABTM'
});
class ApplicationController < ActionController::Base
before_action :authenticate_user!
private
def authenticate_user!
token = params[:token].presence
@current_user = User.find_by(token: token)
end
end
{
"people" : [
{
"name" : "John Doe"
},
{
"name" : "Jane Doe"
}
]
}
[
{
"name" : "John Doe"
},
{
"name" : "Jane Doe"
}
]
module Medium
class PostSerializer < ApplicationSerializer
attributes :title, :description
end
end
describe Medium::PostSerializer do
let(:post) { build :post }
subject { build_serializer post }
{
"title" : "Hello World",
"description" : null
}
{
"title" : "Hello World",
"description" : ""
}
@BenMorganIO
BenMorganIO / medium_post_serializer.rb
Created March 17, 2016 02:18
Serializer Example - Medium Post
module Medium
class PostSerializer < ApplicationSerializer
attributes :title, :description
end
end
describe Medium::PostSerializer do
let(:post) { build :post }
subject { build_serializer post }
@BenMorganIO
BenMorganIO / row_to_json.rb
Created February 1, 2016 00:54
JSON parsing in Postgres instead of Ruby.
ActiveRecord::Base.class_eval do
class << self
delegate :row_to_json, to: :all
end
end
ActiveRecord::Relation.class_eval do
def row_to_json
'[' + row_to_json_result.values.join(',') + ']'
end
@BenMorganIO
BenMorganIO / my_controller.rb
Created September 30, 2015 02:15
base controller example usage
class MyController < BaseController
def index
super MyModel
end
end