Re: Re: Bug with ENUM?

Ara.T.Howard
2005-02-18T21:27:03Z

On Fri, 18 Feb 2005, Jarkko Laine wrote:

> On 18.2.2005, at 23:06, Ara.T.Howard wrote:
>>
>>   valid = %w( one two three )
>>
>>   chosen = @params[''chosen'']
>>
>>   present = valid.include? chosen  # => true or false
>>
>> better (case insensitive)
>>
>>   pattern = %r/#{ choice }/i
>>
>>   present = not valid.select{|choice| choice =~ chosen}.empty?
>
> Ara,
>
> You don''t have to go in such details. You can just use the
in-built
> validation functions Rails offers
> (http://rails.rubyonrails.com/classes/ActiveRecord/Validations/
> ClassMethods.html)
>
> In this case:
> validates_inclusion_of :chosen, :in => valid
>
> Put that (and the definition of valid) in your model class and
you''ll be
> fine.
>
> //jarkko

right you are.  OP seemed to be specifically asking about a method on array
objects though.  sorry for noise.

-a
--
==============================================================================|
EMAIL   :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE   :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself.  --Shunryu Suzuki
===============================================================================