加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – rails 3验证模型的实例方法

发布时间:2020-12-17 02:10:38 所属栏目:百科 来源:网络整理
导读:我想在我的自定义验证方法中调用活动记录验证方法 class Asset ActiveRecord::Base validate :ensure_unique_identification_code validates :name,:uniqueness=true def ensure_unique_identification_code self.identifier="identifier code" #code is gen
我想在我的自定义验证方法中调用活动记录验证方法

class Asset < ActiveRecord::Base
  validate :ensure_unique_identification_code
  validates :name,:uniqueness=>true

 def ensure_unique_identification_code
   self.identifier="identifier code" #code is generated using some helper method of Asset model
  validates :identifier,:uniqueness=>true

 end
end

给出错误

undefined method `validates' for #<Asset:0xb6692dbc>

我们如何在模型的实例方法中调用验证方法

解决方法

请检查此链接(它有答案):
How to call ActiveRecord validators as instance methods (ala Sequel)?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读