When I add my rails code into my jquery I have this problem:
Uncaught SyntaxError: Unexpected token <
Here my controller:
class WelcomeController < ApplicationController
def index
@a = "12345"
end
end
My index.js
jQuery(function($) {
$(document).ready(function($) {
var a = <%= @a %>
var url = "http://www.google.com"
console.log(a)
});
});
I don't know how to fix that, please help me!
index.jsfile isn't rendered byerb. Put it in your views inindex.js.erbinstead and create appropriate action for it.var a = '<%= @a %>'Use this. Wrap it in quotes;in your js code. I suggest you read something about javascripts syntax