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
1 Answer
Reset to default 12Try:
-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("");
});