最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ERB replacement with HAML fails in JS - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Feb 1, 2011 at 11:49 shingara 46.9k12 gold badges102 silver badges105 bronze badges asked Feb 1, 2011 at 11:29 shybovychashybovycha 12.3k6 gold badges53 silver badges85 bronze badges 2
  • Do you mean that the javascript isn't executed? Have you checked what is the response that browser gets (check that from Firebug for example). – Heikki Commented Feb 1, 2011 at 11:36
  • This is actually a pretty important question, not sure why some pple elsewhere are saying .js.haml is unsupported – prusswan Commented Aug 23, 2012 at 16:43
Add a ment  | 

1 Answer 1

Reset to default 12

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("");
    });
发布评论

评论列表(0)

  1. 暂无评论