I''d like to do this: validates_numericality_of :importance, :only_integer => true, :within => 1..5 Actually, I think a better way to express it is: validates_value_of :importance, :within => 1..5 AR should deduce from that line that ''importance'' is supposed to be an integer. Cheers, Gavin
On Sun, 3 Apr 2005, Gavin Sinclair wrote:> I''d like to do this: > > validates_numericality_of :importance, :only_integer => true, :within => 1..5 > > Actually, I think a better way to express it is: > > validates_value_of :importance, :within => 1..5 > > AR should deduce from that line that ''importance'' is supposed to be an > integer.nice idea. or possibly a float iff validates_value_of :importance, :within => 1..5.0 cheers. -a -- ==============================================================================| email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | if you love the sacred and despise the ordinary, you are still bobbing in the | ocean of delusion. --lin-chi ===============================================================================
Hi Gavin, Gavin Sinclair wrote:>I''d like to do this: > > validates_numericality_of :importance, :only_integer => true, :within => 1..5 > >Actually, I think a better way to express it is: > > validates_value_of :importance, :within => 1..5 > >AR should deduce from that line that ''importance'' is supposed to be an >integer. > >just in case you didn''t know already: You can do this combining validates_numericality_of and validates_inclusion_of. Not sure if your post was about doing this with _one_ validation macro or how to do it at all. Sebastian
On Sunday, April 3, 2005, 2:07:25 AM, Sebastian wrote:>>I''d like to do this: >> >> validates_numericality_of :importance, :only_integer => true, :within => 1..5 >> >>Actually, I think a better way to express it is: >> >> validates_value_of :importance, :within => 1..5 >> >>AR should deduce from that line that ''importance'' is supposed to be an >>integer.> just in case you didn''t know already: You can do this combining > validates_numericality_of and validates_inclusion_of. Not sure if your > post was about doing this with _one_ validation macro or how to do it at > all.Thanks, I didn''t know you could do it at all. I looked up and down the API docs for ActiveRecord::Validations::ClassMethods, but this didn''t jump out at me. I think validate_inclusion_of is a bad name for a method that is testing the value of something, but now that I know it, I won''t complain. Using a single validation method would be nice. Thanks again, Gavin