5

我有关于验证的问题有类
/app/models/group.rb

class Group < AbstractModel
  include Localized::Title

  ...

end

/app/models/concerns/localized/title.rb

module Localized::Title
  extend ActiveSupport::Concern
  include ActiveModel::Validations

  include do 
    validates :title_ua, length: {minimum: 3, maximum: 200}, uniqueness: true
    validates :title_ru, length: {minimum: 3, maximum: 200}, uniqueness: true
  end

...

end

当我尝试在模型中使用验证时,它可以工作,但不用担心。请帮助我,我做错了什么?

PS AbstractModel < ActiveRecord::Base, rails 4.2, ruby​​ 2.2.0p0

4

1 回答 1

14

它“包含”不包含。试试这样:

module Localized::Title
  extend ActiveSupport::Concern
  include ActiveModel::Validations

  included do 
    validates :title_ua, length: {minimum: 3, maximum: 200}, uniqueness: true
    validates :title_ru, length: {minimum: 3, maximum: 200}, uniqueness: true
  end

...

end
于 2015-02-03T14:05:16.657 回答