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 arra
Usually, if something is a pain in haml, it means you should refactor the the tricky bit to a helper or partial and call that.
// some_helper.rb
def new_snazzy_select_tag(options = [])
select_tag 'tag_name_here', options.map { |option| [option.id, option.name] }
end
Also, you should use the :javascript filter to render javascript since it will put it in a script tag for you and allow indentation.
Lastly, you can use #{ruby_expression} anywhere in haml, including :javascript filters, which is very handy when you need to output the result of ruby expressions to places that are not directly contents of html elements.
// some_view.html.haml
:javascript
$('#mylink').click(function() {
$('#mylink').after("#{escape_javascript new_snazzy_select_tag(myarray)}");
};