I am having issues getting JQuery to be parsed by ruby.
For instance, the following line of code is supposed to add the @user’s username after the div with id ‘title.’
$('#title').after('<%= escape_javascript(@user.first.username') %>);
However, the output that I receive is a string that hasn’t been parsed at, complete with <
I haven’t found anything specifically posted on this on Stack Overflow and I’ve followed several tutorials unsuccessfully.
Thanks in advance for your help!
erb is parsed before the page loads, so this is inserting the erb code during javascript execution, which doesn’t get parsed at all. A better way to do this one would be to insert JS to set a variable, and then use that variable: