Re: Re: Bug with ENUM?

Ara.T.Howard
2005-02-18T21:06:36Z

On Fri, 18 Feb 2005, Bob Aman wrote:

>> I did on rails, then ar. worked. I suppose you just have to find it
>> yourself :-)
>>
>> Browse from http://ar.rubyonrails.com/
>
> http://ar.rubyonrails.com/classes/ActiveRecord/Validations.html
>
> In any case, lacking the underlying ruby knowledge, I''m not sure
> exactly how to search through the array of valid string values and
> check if the input is among the entries.  Is there a convenient
> .contains? method?

   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?

hth.

-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
===============================================================================