Re: Re: Bug with ENUM?

Jarkko Laine
2005-02-18T21:16:01Z

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


>
> 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
> =======================================================================
> =======> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Jarkko Laine
http://jlaine.net
http://odesign.fi


_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org