Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

just ran into some strange validation problem.

General • Asked by Joe Guerra

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


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.


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.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.