3

I have a js.erb with this basic content:

$("#currencies").html("<%= options_for_select([['Dollar', '$']])%>");

And the html is not being added to the element #currencies.

However if I do it like this:

$("#currencies").html('<option value="$">Dollar</option>');

The html is being updated.

What can be happening?

For debugging purposes I have tried this:

alert("<%= options_for_select([['Dollar', '$']]) %>");

And it doesn't show anything either.

Hommer Smith
  • 26,772
  • 56
  • 167
  • 296

1 Answers1

5

You need to escape javascript with <%=j .. %>

<%=j options_for_select .. %>

or

<%= escape_javascript(..) %>

or

$('some_element').replaceWith('<%=j render 'some/element_template' %>');

from api documentation

Alper Karapınar
  • 2,694
  • 1
  • 25
  • 36