Reputation: 2361
I have a link in my rails layout template that has the following link:
<%= link_to "Sign in", "/login", class: "sign_in" %>
And the following js to hijack the click event:
<script type="text/javascript" charset="utf-8">
$(function(){
$('a.sign_in').on('click',function(e) {
console.log("test");
e.preventDefault();
return false;
});
});
</script>
When I change the link to "login" (so without the slash) it works fine, and the click function executes. However, when I leave it as "/login" it gives me the error:
"Syntax error, unrecognized expression: " + msg rails
I am pulling my hair here... I googled for the error and found a lot of fixes for similar problems but neither seemed to work for me!
EDIT: Issue has been SOLVED, it was related to an unrelated piece of code in application.js hijacking the same link
Upvotes: 1
Views: 10907
Reputation: 13286
In my case
var splitId = "abcd/00001"; $("#employeeChecked_"+splitId).val(chooseDate);
This code have displayed an error message
Error: Syntax error, unrecognized expression: #employeeChecked_abcd/00001 throw new Error( "Syntax error, unrecognized expression: " + msg );
Replaced it
var splitId = "abcd/00001"; var employeeChecked = "employeeChecked_"+splitId; $("input[id='"+employeeChecked+"']").val(chooseDate);
// Solved my issue.
Upvotes: 1
Reputation: 6928
Change
<%= link_to "Sign in", "/login", class: "sign_in" %>
to
<%= link_to "Sign in", "/login", :class => "sign_in" %>
OR to
<%= link_to "Sign in", login_path, :class => "sign_in" %>
It would work.
Upvotes: 0