Usually, if something is a pain in haml, it means that you have to reorganize the complex bit to auxiliary or partial and call it.
// some_helper.rb def new_snazzy_select_tag(options = []) select_tag 'tag_name_here', options.map { |option| [option.id, option.name] } end
In addition, you should use the :javascript filter to render javascript, since it puts it in the script tag for you and allows indentation.
Finally, you can use #{ruby_expression} anywhere in haml, including filters :javascript , which is very convenient when you need to output the result of a ruby โโexpression to places that are not the direct contents of the html elements.
// some_view.html.haml :javascript $('#mylink').click(function() { $('#mylink').after("#{escape_javascript new_snazzy_select_tag(myarray)}"); };
Alex Wayne Apr 14 '10 at 21:19 2010-04-14 21:19
source share