Insomania Insomania - 4 months ago 34
Ruby Question

Validation Error in Active Admin in Ruby On Rails 5

Hi 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,

Please help me to find out the issue.

Answer

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