简体   繁体   中英

RAILS 3 model validation inclusion in 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 via Cygwin The validation does not seem to work, ie it accepts any value for term_type. When using inclusion (or validates_inclusion_of which produces the same fail condition) do I need DB validations matching those in the model? Any issues with Strings I should be wary of?

Term_type is just a string in the DB and not a separate table.

Any pointers much appreciated.

Vince

你尝试过使用过吗?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM