Inline ruby in :javascript haml tag? [duplicate] Inline ruby in :javascript haml tag? [duplicate] javascript javascript

Inline ruby in :javascript haml tag? [duplicate]


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

:javascript   var tab = #{@tab}

Take care of correctly escaping, however.


This is a terrible way to structure code.

Inline JavaScript is bad enough. Inline JavaScript with ERb inside puts you straight into hell.

JavaScript should be in external static files. That way the browser can cache them, and you can use JavaScript as a real programming language.

In your case, I'd recommend something like:

(Haml file)

#tab= @tab

(CSS file)

#tab { display: none }

(Javascript file)

var Tab = $('#tab').innerHTML();

That way everything stays static and maintainable, and you're not mixing JS and HTML.