简体   繁体   中英

Render partial from jQuery ruby on rails

I wanted to render a partial that contains a form inside of view from application js, I am reading the event of attached button without submitting because I need to process the headers of a file CSV before doing submit.

This is the function:

$(document).ready(function () {
  $("#attached_attached_csv").change(function (e) {
    if (e.target.files != undefined) {
      var reader = new FileReader();

      reader.onload = function (e) {
          // this line isn't working - I try of many ways, but none are working
          $("#text").html("<%= j render partial: 'layouts/form') %>".html_safe);
      };
      reader.readAsText(e.target.files.item(0));
    }
    return false;
  });
});

I see also how any people using ajax, but I don't know how to use this for the trigger event of an attached button without submitting, I prob sending without html_safe but I obtain the string:

<%= j render partial: 'layouts/form') %>

My partial is "layouts/form", which is a file with extension html.erb. here share where I found the code for handle the event http://jsfiddle.net/FSc8y/2/ , but it's not important the most important for me its render the embedded ruby form. Thanks in advance.

You can use rails syntax in your javascript files by adding .js.erb extension to the file name like my_file.js.erb .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM