You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a validation like so: requires :names, type: Array[String]
and I also want to accept a null element.
e.g. [null], [null, "name"]
but would not work. requires :names, type: Array[String]
and requires :names, type: Array[String], coerce_with: ->(val) { val.compact if val.is_a?(Array) }
How can I accept array including String and null?
The text was updated successfully, but these errors were encountered:
chicaco
changed the title
How to require an Array param, which have string or elements
How to require an Array param, which have string or null elements
Mar 11, 2016
For a POST request with a type that clearly delineates nil vs. an empty value vs. something else, like JSON, I think you can "just do it".
For a GET request I don't think you can because there's no way to distinguish nil and an empty string in a query. How would you make an HTTP request with an array containing nils in, say, curl?
I have a validation like so:
requires :names, type: Array[String]
and I also want to accept a null element.
e.g. [null], [null, "name"]
but would not work.
requires :names, type: Array[String]
and
requires :names, type: Array[String], coerce_with: ->(val) { val.compact if val.is_a?(Array) }
How can I accept array including String and null?
The text was updated successfully, but these errors were encountered: