[Rails] Re: Correct use of before_validation

2013-06-26 Thread Joel Pearson
Thanks for the tip! If the call to "super" triggers the validation then that should be perfect. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving

[Rails] Re: Correct use of before_validation

2013-06-26 Thread Matt Jones
On Tuesday, 25 June 2013 05:15:06 UTC-7, Ruby-Forum.com User wrote: > > Catching that 0.0 value was the right direction to look in: > > def convert_hours > if hours_before_type_cast && hours_before_type_cast =~ /:/ > hrs, mins = hours_before_type_cast.scan( /(\d*):(\d*)/ ).first >

[Rails] Re: Correct use of before_validation

2013-06-25 Thread Joel Pearson
Catching that 0.0 value was the right direction to look in: def convert_hours if hours_before_type_cast && hours_before_type_cast =~ /:/ hrs, mins = hours_before_type_cast.scan( /(\d*):(\d*)/ ).first self.hours = BigDecimal( ( hrs.to_f + ( mins.to_f / 60.0 ) ), 4 ) end end

[Rails] Re: Correct use of before_validation

2013-06-25 Thread Joel Pearson
I've managed to get the event to fire now, but what I get from STDOUT is 0.0 So I guess that means I'm not receiving a string from input. before_validation :convert_hours protected def convert_hours STDOUT << hours if hours && hours =~ /:/ hrs, mins = hours.scan( /(\d*)