Hello my dear friends. Today we will talk about how we share mustache templates in Rails 3.
Let’s imagine that we have a task, where on first load of the page we show only 10 products. But when user scroll, we should automatically load more products on page (aka continuous pagination).
How it works?
First of all you have to add this gem to your Gemfile and start ‘bundle install':
gem 'smt_rails', git: 'git://github.com/railsware/smt_rails.git'
Next launch generator:
rails g smt_rails:install
Now you can create a directory in ‘app/templates’ mustache templates (these templates ends with ‘.mustache’ by default). Let’s create partial for the product:
You can render this partial in ActiveView:
<%= render "products/product", :mustache => product.as_json %>
var product = … ; come from ajax call as json
var content = SMT['products/product'](product);
Demo application with scroll pagination you can find here
Source code: https://github.com/le0pard/st_rails_example
That’s all folks!
SMT_rails (Shared Mustache Templates for Rails)
Source code: https://github.com/railsware/smt_rails
Most recent posts
- Responsive layout tests with Capybara and RSpec
- SQL Joins Visualizer – build SQL JOIN between two tables by using Venn diagrams
- Flexbox as a solution for browser reflow optimization
- Make AngularJS 1.0.7 work with Jasmine 2.0
- Git housekeeping tutorial: clean-up outdated branches in local and remote repositories
Most popular posts
- API with Ruby on Rails: useful tricks 50,216 views
- Git housekeeping tutorial: clean-up outdated branches in local and remote repositories 25,168 views
- Creation of pure Swift module 23,977 views
- PostgreSQL most useful extensions 20,802 views
- Advanced server definitions in Capistrano 19,203 views