I need to do multiple file uploads using nested form and jQuery. so I wrote an helper using link_to_function method:
def add_document_link(title, form)
link_to_function title do |page|
form.fields_for :documents, Document.new, :child_index => Time.now.to_i do |f|
page << "$('#documents').append('#{escape_javascript(render('/realties/document', :f => f))}');"
end
end
end
this code simply creates a link that, if pressed, renders a new file upload nested form. it surprisingly works, even if I'm using rails3 beta4 (and I know that 'link_to_function' is deprecated)
is there a better way to do the same without using link_to_function or some AJAX call?
thanks in advance ;)
You might want to take a look my project https://github.com/adamaig/complex-form-examples which is derived from some other people's work. The same methods work for rails 3 (i just upgraded the project locally for a test). The big issue is the deeply nested elements, but this project should demonstrate a ujs way of working with jquery and rails generated templates.