Created
November 2, 2011 19:55
-
-
Save jonpaul/1334704 to your computer and use it in GitHub Desktop.
pages, contents, blurbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blurb < ActiveRecord::Base | |
default_scope :order => 'weight ASC' | |
has_many :contents, | |
:foreign_key => "blurb_id", | |
:dependent => :destroy | |
has_many :pages, :through => :contents | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Content < ActiveRecord::Base | |
belongs_to :page | |
belongs_to :blurb | |
validates_presence_of :page_id, :blurb_id | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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