Reputation: 11
I have use Rails params gem for rails params validation
param! :answers, Array, blank: false, required: true do |x|
x.param! :value, String, blank: false, reqiured: true, message: 'Value Can\'t Blank'
end
value is both
params = "some random string" or params = ["some random string", "some random string", "some random string"]
In that params, value key was accept both string and array, I don't how to handle it
Upvotes: 1
Views: 150
Reputation: 31
I did not found anything like or
or a support of multiple types.
Maybe you can use transform
to cast your string to an array (code is not tested):
x.param! :value, Array, blank: false, reqiured: true, transform: lambda { |val| [val].flatten.reject(&:blank?) }, message: 'Value Can\'t Blank'
Upvotes: 1