Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
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"

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.

# 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
module SoftDelete
def destroy
self.deleted_at = Time.zone.now
self.save
end
end
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
require 'rubygems'
require 'crack'
require 'httparty'
module Icontact
# http://developer.icontact.com/
# change to your needs
def self.config
<div id="next-prev-link-container">
<a href="/blog/2010/06/13/a-good-time-to-learn.html" target="_blank">Peer Pressure Learning 30 Series</a>
<br />
<small>&larr; <a href="/blog/2010/06/25/ppl30-day-12-factor.html">Day 12: Factor</a></small> - Day 13: DataMapper - <small><a href="/blog/2010/06/27/ppl30-day-14-html5.html">Day 14: HTML5</a> &rarr;</small>
</div>
/* Forms */
form ol {
list-style: none;
margin: 0 0 1em 0;
}
form ol ol { margin-left: 0; }
form ol li { margin: 0 0 1em 0; }
form ol ol li { margin: 0 0 .25em 0; }
# add a layer of abstraction || obfuscation!
module Somethingable
def self.make(&block)
begin
return true if block.call
rescue
return false
end
end
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_counter
helper_method :counter
protected
def counter
@counter