Enabling RAILS 3 model validation does not work

# ==Schema Information
# Schema version:
# Table name: terms
#  id                 :integer         not null, primary key
...
#  user_id            :integer
#  term_type          :string(255)`

term.rb:

  class Term < ActiveRecord::Base 
validates   :term_type,         :inclusion => { :in => %w(Term Segment Entity Abbreviation) }`

Rails 3.0.3, ruby ​​1.8.7, Windows through Cygwin Validation does not work, i.e. Takes any value for term_type. When using inclusion (or validates_inclusion_of, which creates the same failure condition), do I need database checks that match those contained in the model? Any string problems should I be wary of?

Term_type is just a row in the database, not a separate table.

Any pointers are greatly appreciated.

Vince

+3
source share
1 answer

Have you tried using

validates :field, :inclusion => %{abc ade aeee}
+6
source

Source: https://habr.com/ru/post/1793023/


All Articles