Ruby methods within Javascript within HAML

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-04-14T20:38:55Z Indexed on 2010/04/14 20:43 UTC
Read the original article Hit count: 175

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about haml