I have a backbone.js front-end and Rails backend, and all my template files are in the assets directory.
I want to implement a select list in one of my templates, with the data coming from a controller.
For example, I have an AccountController and I want the user to be able to select from available accounts. Right now, I’ve got an AJAX request to build the accounts select list, but that isn’t efficient.
Is there a way to inject my Rails data into my templates before the templates are sent to the user?
Assuming you are OK with using mustache.js to render your templates, poirot can do exactly what you’re trying to do. With this you can have rails data rendered into the template before rendering the template on the front-end, and you can also use the same mustache template for both back-end and front-end. Keep it DRY yo.
Another way to solve the problem would be to name your JS files like so: example.js.erb, which allow you to render the select HTML or data directly to the JS file, and use it as needed.