ruby on rails - Include route helpers in javascript files -
i'm trying log route's root url console:
app/assets/javascripts/foo.js.erb:
console.log(<%= root_path %>);
however, gives me error in javascript console:
uncaught syntaxerror: invalid regular expression: missing /
how include route helpers javascript files?
worth noting can no problem:
console.log(<%= pi = "3.142" %>); //-> 3.142
however, there weird error when effort set letters string:
console.log(<%= pi = "3.142t" %>); //-> uncaught syntaxerror: unexpected token illegal
i need able log strings letters in if want have route helpers working! :)
erb beingness parsed on server side, before javascript has chance read it. when executed on browser read:
console.log(http://root_url.com);
you can see, missing quotes here. try:
console.log('<%= root_url %>');
javascript ruby-on-rails
No comments:
Post a Comment