I am using Rails 3.1 and Haml. What is the best way to add inline javascript that is generated in something such as a form_for block. I tried the following:
In layouts/application.html.haml,
...
:javascript
yield(:jstemplates)
...
And in my form_for block,
...
= content_for :jstemplates do
= "var my_var='#{generate_template(form, :my_field)}'"
...
Instead, I had to do the following:
...
:javascript
#{@my_javascript}
...
and
...
- @my_javascript = capture_haml do
var my_var='#{generate_template(form,:my_field)}'
...