Skip to content

Instantly share code, notes, and snippets.

@avk
Created February 26, 2009 23:03
Show Gist options
  • Save avk/71187 to your computer and use it in GitHub Desktop.
Save avk/71187 to your computer and use it in GitHub Desktop.
class Site < ActiveRecord::Base
has_many :pages
belongs_to :account
validates_presence_of :url
validates_format_of :url, :with => URI.regexp(['http', 'https'])
validates_presence_of :account_id
validates_associated :account
after_save :create_home_page
def home_page
# url
self.pages.first.url
end
protected
def create_home_page
self.pages << Page.new(:url => url)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment