I have two models
class ComfortFactorSubCategory < ApplicationRecord
has_one :image, as: :imageable, dependent: :destroy
validates :heading, presence: true
accepts_nested_attributes_for :image, :reject_if => lambda { |a| a[:name].blank? }, allow_destroy: true
end
class Image < ApplicationRecord
belongs_to :imageable, polymorphic: true
mount_uploader :name, IconUploader
end
and my admin/comfort_factor_sub_category.rb I have these lines
ActiveAdmin.register ComfortFactorSubCategory do
permit_params do
permitted = [:heading, image_attributes: [:name, :_destroy, :id], additional_instruction_ids: []]
permitted
end
form do |f|
f.inputs do
f.input :heading
f.input :additional_instructions, as: :select, collection: AdditionalInstruction.pluck(:description, :id)
f.fields_for :image do |b|
b.input :name, label: "Image", :as => :file
end
end
f.actions
end
end
when I submit the form with wrong information lets say without heading and validation fail why do I need to select the image again while I did select in first submission