small medium large xlarge

25 Jul 2009, 11:22
Sarun Wongpatcharapakorn (5 posts)

In example it use wibble and it show an error messages. I try different strings and yes messages show as it should, but when I enter number + string like 1www, 2a, or any valid ID with string it didn’t show error messages and successfully add item to cart ( item id 1 in case input 1www). I wonder if I do something wrong or that is normal behavior from what written in the book and how to cope with this situation.

Thank you

27 Jul 2009, 13:26
Dave Thomas (396 posts)

I believe this is a “feature” of Rails. If you want better validation, you can use the Integer method to convert the parameter to a number before passing it to find(): the Integer method raises an exception when given a string that isn’t a valid number. (I believe Rails uses to_i, which accepts leading digits as a valid number, so “123abc”.to_i will equal 123.


You must be logged in to comment