Ruby methods within Javascript within HAML
- by Josh
I have a jQuery script that adds a new field to a form, and this field contains dynamic information from an array. The problem is that I can't figure out how to add an array.each to populate the options of the select field within the javascript without breaking the HAML indentation and causing errors.
Here is my best attempt that does not work:
%script(type="text/javascript")
$('#mylink').click(function() {
$('#mylink').after('<select>
- myarray.each do |options|
<option value="#{options.id}">#{options.name}</option>
</select>);
)};
Also tried it with the :javascript filter with no luck.
EDIT: For whatever reason, I can't get the 4-space indents ( for Markdown ) working here, but I do have it indented properly.