Re: AJAX form within a traditional form

Maybe I should explain what I'm trying to do. I have a form (mostly scaffold code) which I can use to edit a contact. Contacts can have many addresses and my relationship between contact and address reflects this. What I'd like to be able to do is, while I'm editing a contact, have a section for editing, adding and deleting addresses from a contact.

Ideally this section would use some JavaScript and AJAX. For example, clicking 'Add a new address' would make some new fields appear so a new address can be added. Edit and delete should work in a similar way.

Re: AJAX form within a traditional form

The basic gist is, link_to_remote will call an action that generates a small piece of html that gets placed in a div. That html can contain a form_remote_tag that submits to an action and also returns html. You can also use RJS for more complex javascript manipulation, but I would hold of on that.

Re: AJAX form within a traditional form

The basic gist is, link_to_remote will call an action that generates a small piece of html that gets placed in a div. That html can contain a form_remote_tag that submits to an action and also returns html. You can also use RJS for more complex javascript manipulation, but I would hold of on that.

Thanks thabenksta. Much appreciated.

Is it normal practise to write the actions for this functionality on the contact controller or the address controller?

Re: AJAX form within a traditional form

So when 'Add address' is clicked it is replaced with a form to add an address.

The action 'ajax_get_address_form' simply renders a partial which contains the form to add an address. Am I correct in saying that this HTML that is returned should contain the form_remote_tag which submits the form?