Skip to content

Instantly share code, notes, and snippets.

View dja's full-sized avatar

Daniel Jacob Archer dja

View GitHub Profile
@greg-barnett
greg-barnett / gist:878958
Created March 21, 2011 03:15
Delayed::Job belongs_to owner
# db/migrate/#{timestamp}_add_owner_to_delayed_jobs
class AddOwnerToDelayedJobs < ActiveRecord::Migration
def self.up
add_column(:delayed_jobs, :owner_type, :string)
add_column(:delayed_jobs, :owner_id, :integer)
end
def self.down
remove_column(:delayed_jobs, :owner_type)
remove_column(:delayed_jobs, :owner_id)
@henrik
henrik / nullify_blank_attributes.rb
Created November 27, 2010 10:11
ActiveRecord mixin to save NULL instead of empty strings to database.
module NullifyBlankAttributes
def write_attribute(attr_name, value)
new_value = value.presence
super(attr_name, new_value)
end
end
class Video < ActiveRecord::Base
validates_presence_of :title
named_scope :finished, :conditions => { :encoded_state => "finished" }
has_attached_file :video,
:url => ":class/:id/:style/:basename.:extension",
:path => ":class/:id/:style/:basename.:extension",
:storage => :s3
validates_attachment_presence :video