small medium large xlarge

Generic-user-small
19 Feb 2009, 11:47
Stefan Schüßler (1 post)

You can implement @error@ and @human_attribute_name@ to show validation errors from the encapsulated models.

class OrderPresenter

  # ...

  def self.human_attribute_name(attribute_key_name, options = {})
    model, *model_attribute_key_name = attribute_key_name.to_s.split("_") 
    model.classify.constantize.human_attribute_name(model_attribute_key_name.join("_"), options)
  end

  def errors
    errs = ActiveRecord::Errors.new(self)
    self.account.errors.each{|attr,msg| attr == "base" ? errs.add_to_base(msg) : errs.add("account_#{attr}",msg)}
    self.address.errors.each{|attr,msg| attr == "base" ? errs.add_to_base(msg) : errs.add("address_#{attr}",msg)}
    self.credential.errors.each{|attr,msg| attr == "base" ? errs.add_to_base(msg) : errs.add("credential_#{attr}",msg)}
    errs
  end

end

</code>

You must be logged in to comment