Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Quick fix for ActiveModel error_wrapping

#4451

I found this bug when trying to use an ActiveMerchant credit card object in a form. ActiveMercahnt does it's own validations but there aren't keys for fields with no errors so it fails.

The simple fix is:

module ActiveModelInstanceTag
  def error_wrapping(html_tag)
    if object.respond_to?(:errors) && object.errors.respond_to?(:full_messages) && object.errors[@method_name] && object.errors[@method_name].any?
      Base.field_error_proc.call(html_tag, self)
    else
      html_tag
    end
  end
end

All I added was "&& object.errors[@method_name]" to check if the field exists in the errors array. Let me know if you'd like me to submit a patch. This is pretty simple.

Reported by aaronchi · April 22nd, 2010 @ 04:14 AM

State: invalid
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. aaronchi
    aaronchi
    • Assigned user set to José Valim

    April 22nd, 2010 @ 04:48 AM

  2. José Valim
    José Valim
    • State changed from new to invalid

    ActiveMerchant needs to be fixed. The ActiveModel API requires @errors[:foo] to return an empty array in case no error exists in :foo. You can investigate ActiveModel::Lint to see how all the requirements for an ActiveModel Compliant API.

    April 22nd, 2010 @ 08:21 AM