RAILS 3模型验证包含不起作用 [英] RAILS 3 model validation inclusion in does not work

查看:69
本文介绍了RAILS 3模型验证包含不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# ==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通过Cygwin 验证似乎不起作用,即它接受term_type的任何值. 使用包含(或产生相同失败条件的validates_inclusion_of)时,是否需要与模型中的数据库匹配的数据库验证? 我应该警惕Strings的任何问题?

Rails 3.0.3, ruby 1.8.7, Windows via Cygwin The validation does not seem to work, i.e. 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只是数据库中的一个字符串,而不是一个单独的表.

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

非常感谢任何指针.

文斯

推荐答案

您是否尝试过使用

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

这篇关于RAILS 3模型验证包含不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆