Reputation: 3115
I have some questions on jquery in rails3. If I put a function like this in my application.js
. Is it appropriate to put my JS in there rather than in my views?
$(function())
{
$("alert").onclick(function());
....
});
How do I call it within a view? Doesnt the function need an identifier or name? Is link_to_function
a good way?
Upvotes: 0
Views: 174
Reputation: 3236
Proper way of doing it:
$(function()
{
$(".alert").click(function( .... ));
....
});
Don't put this in your views. Just add to to application.js
This attaches a click handler to your links with the class alert
. Function will be called automatically when the click event fires (when you click the link).
Upvotes: 1