This project is archived and is in readonly mode.

#115 ✓stale
Brad Sumersford

validates_confirmation_of does not confirm with decimal column type

Reported by Brad Sumersford | May 5th, 2008 @ 05:12 PM

This may fall under the "why would you want to" category, but the validates_confirmation_of validation does not properly validate decimal (BigDecimal) columns. Example:

create_table :payments do |t|

t.decimal :amount, :precision => 10, :scale => 2

end

class Payment < ActiveRecord::Base

validates_confirmation_of :amount

end

  1. Lets make believe this is string form data

script/console

>> p = Payment.new(:amount => "0.25", :amount_confirmation => "0.25")

>> p.save

=> false

>> p.errors.full_messages

=> ["Amount doesn't match confirmation"]

--------------------------------------

This appears to be due to the fact that the amount_confirmation value is not being cast to a BigDecimal like the amount value is. Adding this hack to the Payment model fixes the issue

def amount_confirmation

column_for_attribute(:amount).type_cast(@amount_confirmation)

end

Comments and changes to this ticket

  • josh

    josh July 17th, 2008 @ 01:09 AM

    • State changed from “new” to “stale”
    • Tag cleared.

    Closing this ticket as stale. If this is still an issue for you, feel free to reopen this ticket or create a new one with an updated description. Remember those unit tests too ;)

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages