Is there a way to use a Ruby loop inside of HAML's :javascript region?

nonopolarity picture nonopolarity · Jun 3, 2010 · Viewed 7.7k times · Source

Inside of HAML, can we have a loop inside the :javascript region?

This will work:

- 10.upto(20) do |i|
  :javascript
    document.getElementById('aDiv').innerHTML += '#{i}';

and this will not:

:javascript
  - 10.upto(20) do |i|
    document.getElementById('aDiv').innerHTML += '#{i}';

can the code above also be made to work as well?

Answer

zed_0xff picture zed_0xff · Jun 3, 2010

this one works

%script
  - 10.upto(20) do |i|
    document.getElementById('aDiv').innerHTML += '#{i}';