Skip to content

Instantly share code, notes, and snippets.

@itchy
itchy / gist:3006708
Created June 27, 2012 20:33
singleton for polymorphic ActiveRecord parent with no persistence
require 'singleton'
class News
include Singleton
# should act as though it has_one :blog
NEWS_BLOG_ID = 10
def blog
Blog.find(NEWS_BLOG_ID)
end
@itchy
itchy / answer.rb
Created December 6, 2011 18:25
Best of 2011
class Answer < ActiveRecord::Base
stream_to :company
end
@itchy
itchy / gist:1439280
Created December 6, 2011 18:22
Worst of 2011
require "#{Rails.root}/vendor/gems/cubeless_base-0.0.4/lib/batch_mailer"
require "#{Rails.root}/app/models/notifier"
# SSJ 11/16/2010
#
# when using in consule do: require 'spec/mailer_send_helper'
# these methods are not in cubeless, but help in testing ...
class BatchMailer
def self.send_batch_mail(tmail)
users = ["scott.johnson@sabre.com"]
# here(tmail.charset)
@itchy
itchy / Validations Gone Wild.rb
Created December 8, 2010 00:21
Worst of 2010 For Scott Johnson
class Task < ActiveRecord::Base
belongs_to :user
belongs_to :location
belongs_to :customer
belongs_to :task_code
validates_presence_of :location_id
validates_presence_of :customer_id
validates_presence_of :job_number
# validates_format_of :job_number, :with => /^[5-9][0-9]{5,100}/