This project is archived and is in readonly mode.

#4451 ✓invalid

Quick fix for ActiveModel error_wrapping

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

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?, self)

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.

Comments and changes to this ticket

  • aaronchi

    aaronchi April 22nd, 2010 @ 04:48 AM

    • Assigned user set to “José Valim”
  • José Valim

    José Valim April 22nd, 2010 @ 08:21 AM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket