Rails+Backbone.js - dynamical loading templates for mustache - ruby-on-rails

Hi
Please anyone tell me how to load a mustache template from other file into my backbone script?
I'd tried a Ajax but he loads it to me too late and view is already prepared...
Anyway... how to load assets/templates/single/index.html.mustache into backbone View and redirect it into View #el element?
Many thanks

Actually, haven't been able to find a gem similar to handlebars_assets for mustache. Maybe something similar for mustache since handlebars is an extension of mustache.
https://github.com/leshill/handlebars_assets

Related

Rendering a react component in Ruby on Rails partial

Is it possible to render a react component in a rails partial through an AJAX call? Basically for performance reasons, I have to do some condition checks in order to render and initialize a react component in rails view. I cannot require the react JS upfront as well. I am thinking about rendering a partial through AJAX call and replacing the html in the view from jQuery. I am using react-rails for this purpose.
I'm not sure if this is the best way to do it. Other alternatives would be helpful too.
checked react-rails source code and had to manually call ReactRailsUJS.handleMount() via javascript.
For me, calling ReactRailsUJS.mountComponents() fixed my issue.

React, Ruby on Rails: jsx vs html.erb

I'm using the react-rails gem to integrate react with rails, and I'm conflicted on how I should organize my code.
Is it preferable that I have my core html in the html.erb files or in the jsx files? Currently, I basically made everything a component. All I do in my html.erb files is using the react_component helper to call those components. For example, I would have a ProfileShow.js.jsx file for my profile page and a EditPost.js.jsx for my edit post page.
What is your suggestion?
I prefer move my react-component's code to js-files. And link them using react_component helper method. It isn't good practice to write your js-code in views.
There are multiple ways to do this.
One of the best solutions I seen so far is to write your react jsx components in an app/assets/javascripts/components folder.
Setup a react gem like https://github.com/shakacode/react_on_rails
that would help with passing on data as props to the view layer as these would be accessible outside react.
I hope this helps.
Cheers.

Is it possible to share HAML templates between Coffeescript (Backbone.js) and Rails 3.2?

Is this possible? I know people use mustache to share templates, but can you use HAML? I would prefer pre compilation.
A quick google search turns up this lib for client-side rendering of HAML . So it would appear that yes, you could share templates between the client-side and server-side of your app.
If you are processing your JS templates server-side first, then the asset pipeline will take care of this with the correct file extension. You wont be able to use the rendered haml template on the client-side though as it will be missing its tags..

Sharing templates beetween JS and Rails using Haml + Mustache

I am trying to make common templates that used both by Rails and the client side, ie in coffescript.
I use hogan_assets and haml_assets to export templates to JS. However I can't find a way to use HAML and Mustache to render server-side views.
Partial solution is described here, but it doesn't work with view helpers, ie, "render partial" doesn't work.
For some unknown reason chaining of handlers, such as .mustache.haml, doesn't work, and I can't find neither good info on Rails template handler nor an example on how to build "chainable" handler.
I've been experimenting with something like smt_rails lately, but I have yet to find a silver bullet.

Rails mixing templating languages

I'm working with a large project where the templates are written in erb. We're getting more and more into client side rendering of parts of the project and we have lots of exact duplicates in mustache of our erb templates.
I'd like to change the erb templates that are replicated in mustache to mustache and print the js templates out from those templates.
I haven't been able to figure out how to mix templating languages in rails though, is this possible? I'd rather not rewrite all the erb templates in mustache.
Thanks!
Maybe Isotope could be useful for you? I never tried it though.
I fear you'd have no direct solution...
An alternative:
You could reuse your good old html created by ruby if you insert in handlebars templates. But it's another js library...
http://www.handlebarsjs.com/

Resources