rails - 关注验证的问题

gre*_*nif 3 validation ruby-on-rails activesupport-concern

关注验证时遇到问题有类
/app/models/group.rb

class Group < AbstractModel
  include Localized::Title

  ...

end
Run Code Online (Sandbox Code Playgroud)

/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
Run Code Online (Sandbox Code Playgroud)

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

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

gom*_*oma 10

这是'包括'不包括在内.试试这样:

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
Run Code Online (Sandbox Code Playgroud)