Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
class AddCart < ActiveRecord::Migration
def self.up
create_table "carts", :force => true do |t|
t.datetime "purchased_at"
t.datetime "reserved_at"
t.datetime "created_at"
t.datetime "updated_at"
end
module SoftDelete
def destroy
self.deleted_at = Time.zone.now
self.save
end
end
# Careful with to_param
class Page < ActiveRecord::Base
validates_presence_of :handle
validates_uniqueness_of :handle
validates_format_of :handle, :with => /^[a-z0-9-]+$/, :message => 'The handle can only contain lowercase letters, numbers and dashes.'
def to_param
handle

Heroku DNS Setup

The Goal

This is an in-progress example of a DNS setup for a Rails app that will allow members to claim a subdomain that is hosted on Heroku. Additionally, subdomain owners should have the option to use their own domain that maps to this subdomain.

The Problem

Heroku has a slightly unique DNS setup, so it seems that some DNS workarounds will be necessary.

has_attached_file :attachment,
:path => ":class/:id/:style_:basename.:extension",
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:s3_host_alias => "assets.whatever.com",
:url => RAILS_ENV == "production" ? ":s3_alias_url" : ":s3_path_url"
# needs refactored...but not today
module ApplicationHelper
def display_address(obj, args = {})
args = {
:address_1 => obj.respond_to?('address_1') ? obj.address_1 : obj.address1,
:address_2 => obj.respond_to?('address_2') ? obj.address_2 : obj.address2,
:city => obj.city,
:state => obj.respond_to?('state_abbrev') ? obj.state_abbrev : obj.state,
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Slides</title>
<script src="jquery-1.3.2.js" type="text/javascript" charset="utf-8"></script>
<script type='text/javascript'>
# in layout...
:javascript
jQuery(document).ready(function($){
#{yield :ready}
});
# in view...
- content_for :ready do
require 'hirb'
module Hirb
module Console
# Simple shortcut to grab a few columns in irb
# Note that you can only use column names
# Usage:
# tab Article.all, :id, :title, :published_at
def tab(output, *fields)
max_width = case fields.size
# this allows you to use a CNAME for multiple environments
# Paperclip only supports multiple access, secret access and bucket
# in your model...
has_attached_file :attachment,
:path => ":class/:id/:style_:basename.:extension",
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:s3_host_alias => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV]["s3_host_alias"],