Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
module Kernel
def ensure_a
self.is_a?(Array) ? self : [self]
end
end
class Thing
attr_accessor :name, :age
end
class Thing < Struct.new(:name, :age)
end
# in config/routes.rb
map.blog "/blog", :controller => "blog"
map.blog "/blog/:id", :controller => "blog", :action => "show", :id => id
# steroids_on_steroids
class Steroids
def initialize
Steroids.new
end
end
ActionController::Routing::Routes.draw do |map|
map.with_options :controller => "info" do |info|
%w[action1 action2 whatever yada1 yada2 yada3].each do |action|
info.send(action, action, :action => action)
end
info.home "/"
info.root
end
form.formtastic fieldset ol li { display: block; margin-bottom:.5em; }
form.formtastic fieldset {border:1px solid #CCC; width:400px; padding:15px; margin:15px;}
form.formtastic fieldset ol li label { display:block; width:200px; float:none; padding-top:.2em; }
form.formtastic legend { margin-bottom: 15px;}
form.formtastic legend span { background-color: #666; padding:8px; color:#FFF; }
form.formtastic .numeric { width:60px;}
@property.asking_price_type == 'Price' ? number_to_currency(@property.asking_price, :precision => 0) : "#{number_to_currency(@property.asking_price)}/SF"
require 'rubygems'
require 'httparty'
module Icontact
# This info was gleaned from developer.icontact.com
# Get a sandbox APP ID from here
APP_ID = "XXXXXXXXXXXXXXXXXXXXX"
module ActiveHash
class Base
def self.has_many(association_id, options = {})
define_method(association_id) do
options = {
:class_name => association_id.to_s.classify,
:foreign_key => self.class.to_s.foreign_key
}.merge(options)
require 'rubygems'
require 'sinatra'
require 'active_hash'
### HAS_MANY AND BELONGS_TO
module ActiveHash
class Base
class << self