Ask A Question

Notifications

You’re not receiving notifications from this thread.

just ran into some strange validation problem.

Joe Guerra asked in General

Can't remember why I added this to my product model.

validates_numericality_of :qty, less_than_or_equal_to: 10, greater_than: 0

but it was causing activerecord errors when I was removing it from Qty. (ie adding it to my cart)

I thought that the validations in the model only affect records when being created (on the new / create method?)

Anyways, i removed that from my model.
Thanks,
Joe

Reply

Did you mean greater_than_or_equal_to: 0 ?

The code right now wouldn't allow the quantity to ever be 0, but that seems like something you'd want to support.

Reply

hmm, ok must have missed that. I've commented out the whole thing.
Definitely, don't need an upper limit either.

hmm, maybe that's why it was in there initially. I didn't want to add a product to the inventory unless it was qty > 0. and when I went to remove all the qty from the product, it gave me that validation error.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.