How to escape HAML for Javascript in Sinatra
Posted
by viatropos
on Stack Overflow
See other posts from Stack Overflow
or by viatropos
Published on 2010-04-15T05:07:07Z
Indexed on
2010/04/15
5:13 UTC
Read the original article
Hit count: 492
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?
© Stack Overflow or respective owner