$(function() {
$("#ll_search").submit(function() {
$.getScript(document.location.pathname + '/index.js.erb');
return false;
});
});
Line 3 in the snippet results in the following error:
ActionController::RoutingError (No route matches [GET] "/labs/index.js.erb").
I’m running Rails 3.1, which means jQuery is default. I triple-checked that a file “index.js.erb” actually exists. jQuery can’t seem to see it though.
Remember that
document.location.pathnamewill give you a root level path, which will (by default) in Rails take you to the public directory (unless a corresponding route exists). If you need to render this js file at request time (not recommended as far as performance) create an endpoint that renders the js and returns it appropriately with the right MIME type.