Double nested forms #478

Closed
Mansari opened this Issue Sep 14, 2011 · 2 comments

Projects

None yet

4 participants

@Mansari
Mansari commented Sep 14, 2011

Hi,

I am using ActiveAdmin had_many form helper to build a form for two has_many associations
Project-->Task-->Notes for example.

Has anyone used this before? I am using it and the forms gets generated just fine, HOWEVER, if I try to add a new project and on the same page add a new task and a new note, the project and task gets saved, but not the note.

I tried doing my own form/controller and it works fine. Is this something that is a bug or a 'feature' that needs to be configured in AA own controllers?

Thanks!
Moh

@macfanatic
Contributor

I have only used this in a limited capacity - i.e., build the references on the page load (limited to 3 for instance), but not an unlimited amount of them.

Note this is typed up from memory, but very close to working:

ActiveAdmin.register Post do

    form do |f|
        3.times { @post.photos.build }
        f.inputs "Post Info" do

        end
        f.inputs "Photos" do
            f.semantic_fields_for :photos do |photo|
                if photo.object.new_record?
                    photo.input :photo, :as => :file
                else
                    text_node ( '<label>Photo</label>' )
                    text_node ( link_to( File.basename( photo.object.path ), photo.object.url ) )
                end         
            end
        end
        f.buttons
    end

end

This approach always gives you 3 new upload fields, in addition to however many photos have already been attached to the post.

@pcreux pcreux closed this Oct 13, 2011
@TMaYaD
TMaYaD commented Oct 21, 2011

I have faced similar issue and tried to debug it. The problem is with how the add Task and Add Note buttons work. The generate the inputs with timestamp as an index. As a result, the add note generates a different time stamp than the one being used by the task field generated with add task.
I'll try to fix the issue and submit a pull request.
Can someone please reopen this issue until it is solved.

@TMaYaD TMaYaD added a commit to TMaYaD/active_admin that referenced this issue Oct 21, 2011
@TMaYaD TMaYaD fixed #478 modified the place holder for NEW_RECORD to contain the mo…
…del_name
8e76652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment