Replacing ERB with HAML Error in JS

Hello!

I spoofed HAML and converted a few musical scores from .erbto .haml. But when I tried to transform the view .js.erb, it just wouldn't execute. For instance. it seems mine is .js.hamlnot fulfilled, but .js.erbworks as it should.

Here's mine .js.erb(which works as well):

<% if @quote.errors.any? && @quote.approved? %>
  $("#data_form").html("<%= escape_javascript(render(:partial => "form")) %>");
<% else %>
  $("#data_grid").prepend("<%= escape_javascript(render :partial => "quote", :locals => { :quote => @quote }) %>");
  $("#quote_author,#quote_body").each(function(i,e) {
    $(this).val("");
  });
<% end %>

And here is what I replace:

-if @quote.errors.any? && @quote.approved?
  $("#data_form").html("#{escape_javascript(render(:partial => "form"))}");
-else
  $("#data_grid").prepend("#{escape_javascript(render :partial => "quote", :locals => { :quote => @quote })}");
  $("#quote_author,#quote_body").each(function(i,e) {
    $(this).val("");
  });

What is the problem and how to solve it?

+5
source share
1 answer

Try:

-if @quote.errors.any? && @quote.approved?
  :plain
    $("#data_form").html("#{escape_javascript(render(:partial => "form"))}");
-else
  :plain
    $("#data_grid").prepend("#{escape_javascript(render :partial => "quote", :locals => { :quote => @quote })}");
    $("#quote_author,#quote_body").each(function(i,e) {
      $(this).val("");
    });
+12
source

All Articles