If you'd like to respond to jQuery's GET request with snippets of HTML you could consider rendering a partial layout (which won't include the full application layout). In your controller the response may look like:
def templates
@templates = DocumentTemplate.all
if request.xhr?
render :partial => 'templates', locals: {:templates => @templates}
else
# respond with your normal layout if required
end
end
Then in your app/views/documents/
folder create a partial file called _templates.html.haml
(or .erb). Note the leading underscore in partial names.
You'll have access to a templates
local variable to loop over in your partial file (syntax here is for HAML):
- templates.each do |template|
# do what's required to present each template instance here
Then your jQuery GET request should receive just the partial snippets of HTML:
$.get("/documents/templates", function(data) {
console.log('data');
alert("Load was performed.");
});