1

Is it possible to use standard Rails validations with a Postgres array? I have a service_area column which accepts an array of zip codes. It works well enough, though when I try to use validations for numericality and length, the validators throw errors. Input such as 78702, 78704, 78705 gets the error messages is not a number and is the wrong length. It appears that Rails is trying to validate them as a string, rather than as an array of five digit zipcodes. Is there some way to inform the validator that it needs to parse the input as an array? Thanks!

1 Answer 1

1

Is there something stopping you from converting it to array explicitely like this?

"1, 2, 3".split(',').map(&:to_i)
Sign up to request clarification or add additional context in comments.

2 Comments

The question would be how'd I'd send that array to the validators instead of the string.
Without viewing your code I can only recommend to try out postgres_ext gem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.