Rails - Using jQuery to populate a form -


on page have following:

<span id="attach-file" class="link">attach file</span>   <div id="attach-file-form"> </div> 

give attaching file not common use case, don't want attach-file-form elements present on load, slow down.

what happen user clicks "attach file", jquery ajax get form , inject inside of attach-file-form.

what's right way in rails go this?

in jquery have:

$("#attach-file").live("click", function() {     custom method in attachment controller     inject inside div }); 

does sound right?

having file upload form present on page hidden have pretty 0 impact on performance of site. i'd recommend defaulting file upload form hidden, , triggering display of form when button clicked.

then jquery code can simple as:

$("#attach-file").live("click", function() {   $("#file_upload_form").show(); }); 

if need server, can use jquery.get method make call rails controller, can output form you:

$("#attach-file").live("click", function() {   $.get("/controller/action", function(html) {     $("#file_upload_form").html(html);   } }); 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -