I would like add Javascript/jQuery code to my Rails 3 application that will get data from the server and update the page accordingly.
I thought to use jQuery’s $.get() method:
$.get("/get_data_about_page?page=5", function(data) {
alert("Returned data: [" + data + "]");
});
However, I don’t want users to access get_data_about_page via URL.
How could I disable such access ?
Realistically you can’t stop someone from scraping it if they’re determined…
You could set a variable in the session when the main page is loaded and then protect the AJAX action so that it only responds if the session variable is set – this would prevent naive use of the URL but it’s not foolproof.