Skip to content

Instantly share code, notes, and snippets.

@leehambley
Created June 15, 2009 12:43
Show Gist options
  • Save leehambley/130077 to your computer and use it in GitHub Desktop.
Save leehambley/130077 to your computer and use it in GitHub Desktop.
class Address < ActiveRecord::Base
belongs_to :customer
validates_presence_of :line_1, :city, :postcode
validates_format_of :tag, :with => MVOR::Patterns.dashed_word, :allow_blank => true
belongs_to :addressable, :polymorphic => true
def expendable?
# pending
true
end
end
class Customer < User
# The rest of the `user` attributes are implicitly protected by
# an explicit declaration of accessible attributes in the
# User class.
attr_accessible :business, :account_address, :addresses
has_many :orders
has_many :addresses, :as => :addressable
accepts_nested_attributes_for :addresses
has_one :account_address, :as => :addressable, :class_name => 'Address', :conditions => ['tag = ?','account-address']
accepts_nested_attributes_for :account_address
# ..... snip .....
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment