Sha256: 9b719e39a314fba77d1963a11ee35888a8eae43143cf0db9aa11f54d1fc87f02

Contents?: true

Size: 992 Bytes

Versions: 7

Compression:

Stored size: 992 Bytes

Contents

class Person < ActiveRecord::Base

  has_custom_attributes :telephone => :string, :email => :string do |fields|
    fields.telephone :work, :private, :mobile, :fax
    fields.email :work, :private
    fields.date :born_on, :wed_on, :died_on, :on_model => [:born_on]
  end

  def attribute_email(errors)

  end

end

class Product < ActiveRecord::Base

  has_custom_attributes :url => :string

  has_custom_attributes :size => :float do |fields|
    fields.size :width, :height, :depth
    fields.size :validate_all_with => :attribute_size_validation
    fields.url :details, :on_model => {:details => :details_url}
    fields.date :in_stock_since, :validate_with => lambda { |attribute| attribute.errors.add(:value, "must be after 2010") if attribute.value.to_date.year < 2010 }
  end

  def attribute_size_validation(attribute)
    attribute.errors.add(:value, "should be between 1 and 10") if attribute.value < 1 or attribute.value > 10
  end

end

class Location < ActiveRecord::Base

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
custom-attributes-0.2.27 spec/models.rb
custom-attributes-0.2.26 spec/models.rb
custom-attributes-0.2.25 spec/models.rb
custom-attributes-0.2.24 spec/models.rb
custom-attributes-0.2.23 spec/models.rb
custom-attributes-0.2.22 spec/models.rb
custom-attributes-0.2.18 spec/models.rb