class Component < Sequel::Model
        plugin :validation_helpers
        
        def validate
                super
                validates_presence [:batch_id, :ingredient_id, :percentage]
                validates_numeric :percentage
        end
end

        >> Component.first.values
        => {:percentage=>#<BigDecimal:101f6bbf0,'0.1E3',4(12)>, :name=>"Other", 
:batch_id=>"350b730a-2384-11df-9419-00065b3f562c", 
:ingredient_id=>"4ace354c-2357-11df-8826-00065b3f562c"}

        >> c = Component.new
        => #<Component @values={}>
        >> c.ingredient_id = "4ace430c-2357-11df-9ce0-00065b3f562c"
        . . .
        >> c.valid?
        => false

So far so good. . . .

        >> c.batch_id="375a4e3c-5fc1-11df-94f7-00065b3f562c"
        => "375a4e3c-5fc1-11df-94f7-00065b3f562c"
        >> c.valid?
        => true

What? But .percentage isn't even defined yet . . .

        >> c
        => #<Component 
@values={:batch_id=>"375a4e3c-5fc1-11df-94f7-00065b3f562c", 
:ingredient_id=>"4ace430c-2357-11df-9ce0-00065b3f562c"}>
        >> c.percentage = 50
        => 50
        >> c.valid?
        => true
        >> c.ingredient_id = nil
        => nil
        >> c.valid?
        => false

I cannot figure out why the validation system is correctly monitoring the two 
_id parameters, but completely ignoring the percentage. 


-- 
You received this message because you are subscribed to the Google Groups 
"sequel-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/sequel-talk?hl=en.

Reply via email to