简体   繁体   中英

Rails model validation - validates_inclusion_of

I am having torubles with my model. I have the code:

 class Typeofaid < ActiveRecord::Base
  validates_inclusion_of :type, :in => %w(Food Water Health)
end

But whenever I type 'Food' etc in the box I get

`1 error prohibited this typeofaid from being saved:

    * Type is not included in the list
`

Can anyone help?

I think you have to facturize your model using the type attribute instead of just entering some value using an input box.

"type" is a reserved column for single table inheritence in Rails.

将其更改为以下代码,并尝试在Rails3中正常运行

validates :type, :inclusion => {:in => %w(Food Water Health)}

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