Георгий Миллер Георгий Миллер - 2 months ago 11
Ajax Question

Convert .js.erb to js.haml

I have an ajax code that removes posts from the page:

$("#post_delete").on("ajax:success", function(data){
$("#<%= j @post.id.to_s %>").fadeOut();
});


It works only in the erb format, but when I try to use the haml I recieve an error - "Illegal nesting"

$("#post_delete").on("ajax:success", function(data){
$("#" + "#{j @post.id.to_s}").fadeOut();
});

Answer

In haml you'd have to write your js code like this :

:javascript
  $("#post_delete").on("ajax:success", function(data){
    $("#" + "#{j @post.id.to_s}").fadeOut();
  });