Friday, December 16, 2011

[Rails] Model validation and Aray

How to validate a aray in model?

In form I have a multiple select option, that returns a array

(in model I convert array to string and save it to database)

array can only have values ['A','B','C','D','E','']

So how can I valdate that some value is not a X or Y ?

The model code is:


attr_accessor :categories

def categories
if self.category
@categories = self.category.split
else
@categories = ['']
end
end

def categories=(xxx)
@categories = xxx
return if xxx.blank?
self.category = xxx.join(" ")
end

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate