How to include Ruby string in JavaScript -
i have ruby code:
<%= "hello #{@namevar}" if condition %>
i can include ruby snippet in js in following way-
<script> var v1="<%= @user.name %>" </script>
but can't embed previous code in javascript.
i have tried following:
var v2="<%= \"hello #{@namevar}\" if condition %>";
but didn't work.
thanx.
your attempt correct, don't need escape double quotes inside ruby code though:
var v2="<%= "our funding ask #{@startup.funding_ask_text}." if @startup.try(:funding_ask_text) %>";
Comments
Post a Comment