Suppose you have a page with two columns of content. For whatever reason, you wish to retrieve the HTML content of one of those columns after the page has loaded, via an AJAX re
If you want to use the approach the OP proposed, I would recommend moving it to a separate application.js file and use unobtrusive JS. I wouldn't recommend putting the JS inline on the page itself.
# index.html.erb
# application.js
$(function() {
$.ajax({
url: "...",
success: function (html) {
$("#content").append(html);
}
});
});
# controller.rb
# empty placeholder
def index
end
This fires off the ajax request automatically without you having to put it on every page. It's better practice. I wouldn't call it optimal, but slighty m