I'm converting an html.erb into html.haml. I have some jquery in an erb which is..
:javascript
$(".level").live("click", function() {
//..some code
<% if @milestone %>
milestone = "&milestone=<%= @milestone%>";
<% end %>
//..some code
});
I want to convert the if statement into haml and for that I'm doing..
- if @milestone
milestone = '&milestone="#{@milestone}"'
but this does not work and gives me a syntax error on "if @milestone"
What am I doing wrong? Can you not mix jquery and haml?
Inside the
:javascript
filter (or any filter) code isn’t treated as Haml, so you can’t use things like- if ...
. However you can use interpolation with#{...}
inside filters. In your case you could do something like:That is a bit unwieldy with the nested interpolated parts, so you might want to move it into a helper method, something like:
Then your Haml would look like