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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With