Skip to content

Instantly share code, notes, and snippets.

@jonpaul
Created November 2, 2011 19:55
Show Gist options
  • Save jonpaul/1334704 to your computer and use it in GitHub Desktop.
Save jonpaul/1334704 to your computer and use it in GitHub Desktop.
pages, contents, blurbs
class Blurb < ActiveRecord::Base
default_scope :order => 'weight ASC'
has_many :contents,
:foreign_key => "blurb_id",
:dependent => :destroy
has_many :pages, :through => :contents
end
class Content < ActiveRecord::Base
belongs_to :page
belongs_to :blurb
validates_presence_of :page_id, :blurb_id
end
class Page < ActiveRecord::Base
has_many :blurbs,
:through => :contents
has_many :contents,
:foreign_key => "page_id",
:dependent => :destroy
validates_presence_of :title
has_friendly_id :title, :use_slug => true
def copy!(blurb)
contents.create!(:blurb_id => blurb.id)
end
def copied?(blurb)
contents.find_by_blurb_id(blurb)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment