I am a little confused why this is not the problem that is most often addressed, but here.
I have a Rails application that usually generates my views. I have dynamic content on an interface.
I want to make an AJAX call, return JSON and populate the dynamic parts of the application. I would use the JS template library for this.
I DO NOT want to make an AJAX call, Rails processes the view and sends all the HTML back. I want the response to be JSON, so that it reduces processing and posting time.
The problem is that the HTML that I am generating dynamically is the same HTML that I statically statically load on the Rails page (I think AJAX pagination). HTML, naturally, in my ERB files. But when I generate more content (say, page 2), I obviously cannot access the ERB files and must duplicate the HTML in the JavaScript template file.
Is there a solution that allows me to share my views between Rails and JS? (I understand that trying to mix ERBs with JS rendering is a bit uncomfortable ... loops, conventions, etc.)
Do people usually agree to render HTML and send it by wire? Or do they inconveniently execute JavaScript when loading a page for rendering using JS templates?
javascript ruby-on-rails templates
Mike
source share