- how can I run ruby code inside javascript in haml?
- if I use
var = #{message}
in my example I getundefined local variable or method message
- when I move
- message = 'it works'
above:javascript
everything works fine
I want to run iteration .each
inside :javascript
. See the last code sample for what I need in final javascript code. Where I need to loop few ruby variables (or one hash of hashes of hashes?) to get this. Data (='basics') can have few elemenets. It can have children with few elements etc.
SO this haml code
%html
%head
:javascript
$(document).ready(function() {
- message = 'it works'
var = message
});
%body
- message2 = 'hi'
= message2
%div{:id =>"jstree"}
gives me this html code
<html>
<head>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
- message = 'hi'
var = message
});
//]]>
</script>
</head>
<body>
hi
<div id='jstree'></div>
</body>
</html>
The final javascript code I want to produce using haml is the javascript variable
var data = [{
data: "basics",
attr: {},
children: [
{data: "login", attr: {run: "run"},
children: [
{data: "login", attr: {}}
]
} ,
{data: "Academic Year", attr: {run: "run"},
children: [
{data: "login", attr: {}},
{data: "Academic Year", attr: {filter: "mini", SOF: "yes"}}
]
}
]
}];