Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERB replacement with HAML fails in JS

Greetings!

I've been fooling around with HAML and converted a few view partials from .erb to .haml. But when i tried to convert .js.erb view, it just wont execute. E.g. seems my .js.haml is not executed while .js.erb works as it should be.

Here's my .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's what i'm replacing it with:

-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's the problem and how to solve it?

like image 425
shybovycha Avatar asked Feb 01 '11 11:02

shybovycha


1 Answers

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("");
    });
like image 114
PeterWong Avatar answered Sep 27 '22 22:09

PeterWong