Search code examples
ruby-on-railsrubyvalidationrails-models

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:

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

When I use same thing on frontend model then it works fine, don't know what's going on.


Solution

  • 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