Whitelist value using strong options in Rails 4

Can strong parameters be used to ensure that the attribute is filtered out with a white list of possible values?

For example, I have the age of the parameter that I want to ensure in order to have only these values ​​[10,20,30,40,50]. Is it possible to use the logic of strong parameters to make sure that?

thank

+2
source share
1 answer

Quick response

No! Strong parameters allow you to filter keys only from the hash, regardless of its value.

Long answer

! , , validations:

class MyModel < ActiveRecord::Base
  validates :value, inclusion: { in: [1,2,3] }
end
+2

Source: https://habr.com/ru/post/1682890/


All Articles