Skip to content

Instantly share code, notes, and snippets.

View revans's full-sized avatar
🤠
Building Empires

Robert Evans revans

🤠
Building Empires
View GitHub Profile
module Test
extend self
def name
@name ||= "My name"
end
def read
@name
end
@revans
revans / users_controller.rb
Last active August 29, 2015 14:14
Strong Params
class UserController < ApplicationController
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
...
else
...
end
@revans
revans / fixture_mock.rb
Created September 3, 2014 14:56
Rails Fixtures being used for Mocks
require 'ostruct'
require 'yaml'
#
# A quick and dirty example of something that could be inside of rails to provide
# a stupid simple mock for a model object that has an associated fixture.
#
# ==== Example
#
@revans
revans / demo.rb
Last active August 29, 2015 14:04
How to get the Next/Previous Record from an object. I'm using Rails 4.1.4, PostgreSQL 9.3.4 for the examples.
# Demo Database Object Schema:
#
# * name, string
# * status, integer
# * created_at, datetime
# * updated_at, datetime
#
class Demo < ActiveRecord::Base
include BaseScopes
@revans
revans / LocalTimezoneDatabase.mkd
Last active June 8, 2020 12:08
This is a pretty rough explanation, with some examples, of how to setup a PostgreSQL database with PostGIS, and build your timezone table that you can query, given a latitude and longitude.

Installing and Setting a Timezone database

We're using Rails 4, PostgreSQL 9.3.4, and PostGIS 2.1.2.

Creating a Postgis enabled Postgresql template

createdb -E UTF8 template_postgis
createlang -d template_postgis plpgsq
psql -d template_postgis -c "CREATE EXTENSION postgis WITH SCHEMA public;"
@revans
revans / geo.rb
Last active August 29, 2015 14:00
class Geo
def self.get(coords)
sql = <<-EOF
SELECT ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":#{coords}}'))
EOF
ActiveRecord::Base.connection.execute(sql)
end
end
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMOI+IZDMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM8=+++++++I7DMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM+++++++++++777$MMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM++++++++++++?7777MMMMMMMMMMMMMMMMMMMMMMMMMMMM
$(document).watermark(
// "position" : "bottom-right",
// "opacity" : 30,
// "className" : "watermark",
"path": "/assets/watermark.png"
);
# MODEL
class Case < ActiveRecord::Base
include Eventable
has_many :tasks
concerning :Assignment do
def assign_to(new_owner:, details:)
transaction do