I'm facing an issue with my link_to setup. Here's what I have:
<%= link_to "Load More", comments_feed_path(@post.id), :id => 'my-link', :remote => true %>
In my application.js file, I have the following code:
$( document ).ready(function() {
$('#my-link').bind('click', function() {
alert('Hooray!');
//event.preventDefault(); // Prevent link from following its href
});
});
However, nothing happens when I click on the link. It only works if I use inline JavaScript, like this:
<%= link_to "Load More", comments_feed_path(@story.id), :id => 'my-link', :onclick => "test()", :remote => true%>
In my application.js, I define the test function as follows:
function test(){
alert('test');
}
Can anyone suggest what might be missing in my initial setup?