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.

validates_confirmation_of does not confirm with decimal column type

#115

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

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. josh
    josh
    • 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 ;)

    July 17th, 2008 @ 01:09 AM