4

I have an Active Admin model, :gallery, and it has a nested paperclip resource, :images. :gallery has_many :images.

:gallery has a field, :title, which is required.

When I submit without a title, the other fields persist (:description, :location) but the nested resource becomes blank.

Is there a way to build the resource before validating so it persists after a failed validation check?

f.inputs "Images" do 
      f.has_many :images do |i| 

          i.input :image,
                :as=>:file,
                :multipart => true, 
                :label => "Image" 
              end
    end
Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148

1 Answers1

1

Please check that you added these required things in Gallery model

 attr_accessible :images_attributes

and

 accepts_nested_attributes_for :images, :allow_destroy => :true
Santosh
  • 1,251
  • 9
  • 15
  • No joy, those are in place but the form field does not persist if the form fails validation – Mild Fuzz Nov 19 '12 at 16:58
  • @MildFuzz It will be helpful for us if you provide more detailed code from controller side and from view side because I think you don't need hook for that. Rails takes care for nested form if you added code properly. – Santosh Nov 19 '12 at 17:05
  • I have added the image part of the form. I am not sure how much else is useful. – Mild Fuzz Nov 19 '12 at 17:08