I'm writing a Sinatra + Haml app, and in my Javascript code, I want to be execute some Ruby. In erb, the following works:
<script type="text/javascript">
$(function() {
<% @persons.each do |person| %>
$("#<%= person.id %>").attr("style", "<%= person.style %>");
<% end %>
});
</script>
But how would I write this in Haml? I tried something like
:javascript
$(function() {
- @persons.each do |person|
$("##{person.id}").attr("style", "#{person.style}");
});
But the Ruby code gets rendered as code instead of getting executed.