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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -