Skip to content

Instantly share code, notes, and snippets.

View davejachimiak's full-sized avatar

Dave Jachimiak davejachimiak

View GitHub Profile
@notification = Notification.find(11)
@notification.cohabitant_ids
# => [2, 3, 6]
@notification.cohabitants.each { |c| puts c.contact_name }
# => Cool Lady
# => Cool Guy
# => Super Awesome Dude
@davejachimiak
davejachimiak / create_cohabitants_notifications.rb
Created June 27, 2012 02:45
Rails 4 join table migration
class CreateCohabitantsNotifications < ActiveRecord::Migration
def change
create_join_table :cohabitants, :notifications
end
end
@davejachimiak
davejachimiak / create_cohabitants_notifications.rb
Created June 27, 2012 02:44
Rails 3 join table migration
class CreateCohabitantsNotifications < ActiveRecord::Migration
def change
create_table :cohabitants_notifications, :id => false do |t|
t.string :cohabitant_id, :null => false
t.string :notification_id, :null => false
end
end
end
@davejachimiak
davejachimiak / inclusion.rb
Created June 9, 2012 16:50
:inclusion validator
class Resource < ActiveRecord::Base
module Types
ACTIVE = 'active'
CANCELLED = 'cancelled'
CEASED = 'ceased'
DITCHED = 'ditched'
MEDIA = 'media'
ONE_TIME = 'one time'
ARCHIVED = 'archived'
end