简体   繁体   English

Ruby On Rails 5中Active Admin中的验证错误

[英]Validation Error in Active Admin in Ruby On Rails 5

I am trying to add validation in Active Admin model, and doing it as follow: 我正在尝试在Active Admin模型中添加验证,并按照以下步骤进行操作:

ActiveAdmin.register Skill do

  permit_params :title, :text, :status
  validates :title, length: { maximum: 20 }, presence: true

end

and it gives following error: 它给出了以下错误:

undefined method `validates' for # ActiveAdmin::ResourceDSL:0x007f576cab00c0 #ActiveAdmin :: ResourceDSL:0x007f576cab00c0的未定义方法`validates'

When I use same thing on frontend model then it works fine, don't know what's going on. 当我在前端模型上使用相同的东西时,它可以正常工作,不知道发生了什么。

Try to add validation in the Active record model instead in the active admin. 尝试在活动记录模型中而不是在活动管理员中添加验证。

Add

validates :title, length: { maximum: 20 }, presence: true

in the Skill model Skill模型中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM