[RUBY] I want to limit the input by narrowing the range of numbers

【Overview】

1. Conclusion </ b>

2. How to use </ b>

3. Supplement </ b>

  1. Conclusion

Use validates_inclusion_of: (column name), in: (number) .. (number) </ b>!
2. How to use

You can specify the range of validation numbers!

models


validates_inclusion_of :

For ": (colon) and after", enter any name set in the migarte folder or DB column! The location to be described will be any folder name of models!

models


in:..

For the part, enter the number you want to range before and after ".."!
For example, from 100 to 2000

models


validates_inclusion_of :item_price, in:100..2000

By doing so, you can only enter 100-2000!

  1. Supplement

Also, if you want to change the error bundling name, after in: 100..2000

models


, message: "outside the limits(Freely named) "

If you enter

"item_price (depending on column name) outside the limits"

Can be displayed!

Recommended Posts