gpt4 book ai didi

ruby-on-rails - rails - 关注的验证问题

转载 作者:行者123 更新时间:2023-12-04 06:33:41 24 4
gpt4 key购买 nike

我在验证方面遇到问题
有课
/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

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

附言AbstractModel < ActiveRecord::Base,
rails 4.2, ruby 2.2.0p0

最佳答案

它是“包括”不包括。像这样尝试:

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

关于ruby-on-rails - rails - 关注的验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28300354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com