On 16 June 2010 11:34, Stanislav Orlenko <[email protected]> wrote: > Hi > I have a field called "cost": > > <%= f.text_field :cost, :size=>2, :maxlength=>4 %> > > I want to check that user enter numeral value and this value is integer > > In post.rb (model): > > def cost_validate_int > errors.add_to_base("Error message") unless cost.is_a?(Fixnum) > puts "### #{cost}: "+cost.class.to_s > end > > When I enter in field 100 I get: > > ### 100: Fixnum > > when I enter 10.1: > > ### 10: Fixnum > > when I enter 'asdf': > > ### 0: Fixnum > > I completely can't understand what happen. In migration: > > t.integer :cost > > I think ActiveRectord converts value to Fixnum because in migration this > field signed as integer
How is the string you enter getting into the cost attribute? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

