Skip to content

Instantly share code, notes, and snippets.

@joakimk
Created March 21, 2013 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joakimk/5213642 to your computer and use it in GitHub Desktop.
Save joakimk/5213642 to your computer and use it in GitHub Desktop.
How to handle serialized associations with minimapper that can be validated.
class Address
include Minimapper::Entity
attribute :street
attribute :postalcode
attribute :city
attribute :country
validates :street, presence: true
end
class Customer
include Minimapper::Entity
attribute :name
attribute :phone
attribute :address_attributes
def address
@address ||= Address.new(address_attributes || {})
end
validates :name, presence: true
validate :validate_address
def validate_address
errors.add(:address_attributes, "invalid") unless address.valid?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment