0

I am using this form below in admin portal to create a new record but somehow required: true is not working. I have using rails 5. Any idea where I could be going wrong?

ActiveAdmin.register Workers do
 permit_params :name, :type, versions: []

 form(html: { multipart: true }) do |f|
    f.inputs do
    f.input :name, as: :string
    f.input :type, as: :string
    f.input :versions, as: :select, input_html: { multiple: true, required: true }
    end
    f.actions
 end
end
user12763413
  • 1,177
  • 3
  • 18
  • 53
  • 1
    What does "is not working" mean? Please describe in detail what you expect to have happen vs what actually happens. Please do not use vague language like "not working" -- use specific explanations of behaviors. – anothermh Mar 23 '20 at 22:11
  • @anothermh what I mean by not working is that I am able to create the record without even making a selection in the versions field which I don't want. I want a record not to be created until a selection is made in versions field. – user12763413 Mar 23 '20 at 22:13
  • @anothermh I am trying in active_admin. So not sure how to implement this active record validation in active admin. – user12763413 Mar 23 '20 at 22:25
  • 1
    But at its core, ActiveAdmin relies on Rails. If you tell your Rails model to disallow saving without a field set then it will resolve the issue you've described. If you're hoping to rely on HTML trickery to prevent the form from submitting without a field defined without also restricting it in the model, then you're going about it wrong. – anothermh Mar 23 '20 at 22:37
  • Yes you are right. Your idea worked. Thankyou @anothermh – user12763413 Mar 23 '20 at 22:47

0 Answers0