How to escape HAML for Javascript in Sinatra
- by viatropos
I would like to return a list/combobox from an ajax request ("Which on of these do you like?" type thing). I would like to write that little snippet in HAML, which converts it to HTML, but when I do, the page goes blank. I'm assuming this is because the HTML isn't escaped.
Is there a way to escape HAML so I can do $("#mydiv").html(response);?
Here's the method:
post "/something" do
# process...
haml :"partials/_select", :layout => false, :locals => {:collection => choices}
end
... the haml template:
%select
- collection.each do |item|
%option{:value => item.to_s}= item.to_s
... and the javascript:
success: function(responseText, statusText, xhr, $form) {
$(".dialog_content").append(responseText);
}
I have tried the sinatra_more plugin and the escape_javascript method, but there's problems with the haml buffer in sinatra. Any ideas?