Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

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

"1, 2, 3".split(',').map(&:to_i)
share|improve this answer
    
The question would be how'd I'd send that array to the validators instead of the string. –  timothycommoner Aug 26 '13 at 23:25
    
Without viewing your code I can only recommend to try out postgres_ext gem. –  x3qt Aug 27 '13 at 2:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.