Inline ruby in :javascript haml tag?

Alex Fox picture Alex Fox · Aug 19, 2011 · Viewed 32.3k times · Source

Hey is there a way I can do this in haml?

:javascript
   var Tab = <%= @tab %>

I could just add a helper I guess like:

<script>
  var Tab = '<%= @tab %>'
</script>

But it'd be nice to use HAML!

Answer

Arnaud Le Blanc picture Arnaud Le Blanc · Aug 19, 2011

You can use the string interpolation syntax (#{...}) :

:javascript
   var tab = #{@tab}

Take care of correctly escaping, however.