In the following A and B should be equivalent but only version A works. The rails string evaluation seems broken or occurring too early/late or something. Any ideas?
<% content_for :main do %>
<script type="text/javascript">
$(function(){
//$("#users-new").dialog(); //A
$(<%= "\"#users-new\"" %>).dialog(); //B
});
</script>
<div id="users-new">
testing
</div>
<% end %>
Rails3+ HTML encodes the content in
<%= ... %>by default. That means that your B comes out like this:and that makes no sense in JavaScript. You want one of these:
Either of those will give you the JavaScript that you’re expecting: