-1

I'm working on displaying JSON from ajax request with Ruby on Rails but would like to know the following as it would help in the way I layout my code.

Does server immediately render haml/erb partials inserted via javascript loop via javascript escape function(rails) or would javascript loop finish inserting partials and then server would render all partials? Rails 4.2.4

Will see if I can test this to find out in the mean time.

1 Answer 1

0

Found it, server renders all inserted partials at one time.

Tested with looping though, setting console logs, inserting partials and setting timeouts. Partials render all at once but even before console log shows message. Have more questions now but will have to look online for more info.

// Lets Begin
console.log("Now... Lets begin js.erb");

var data = "<%=  escape_javascript(@data.to_json.html_safe) %>";

handler = JSON.parse(data);

console.log(handler);
console.log("this was the hanlder");

// Javasscript now has the data!! Lets begin to manipulate it.
$("#button").fadeOut("slow");

// Loop to test output
for (i in [1,2,3,4,5,6]){
  setTimeout(function (){
    console.log("Here we go");
  },5000)
  $("#table").fadeIn("slow");

  $("#table").append("<%= escape_javascript(render 'table') %>");
  setTimeout(2000)
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.