This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProductsController < ApplicationController | |
| def index | |
| @products = Product.all | |
| if params[:product_id].present? | |
| @product = Product.find(params[:product_id]) | |
| end | |
| if params[:product_id].present? and request.xhr? | |
| render 'product', layout: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="container"> | |
| <div class="header"> | |
| Header - <a href="/products/">Product List</a> | |
| </div> | |
| <div id="product_details" style="display: none"> | |
| <% if @product.present? %> | |
| <%= render file: 'products/product' %> | |
| <% end %> | |
| </div> | |
| <ul class="products" id="product_list" style="display: none"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h1><%= @product.name %></h1> | |
| <div> | |
| <img src="<%= @product.image_url%>"/> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Model to hold the current state | |
| # position: last scrollTop before clicking an item | |
| # state: Can be ITEM_VIEW or PRODUCT_LIST | |
| # productDetailsHTML: The HTML for the detail view | |
| class window.ProductViewState extends Backbone.Model | |
| @PRODUCT_LIST = 'product_list' | |
| @ITEM_VIEW = 'item_view' | |
| # View to manage transitions between two states | |
| class window.ProductView extends Backbone.View |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if result.blank? | |
| Rails.cache.write(name + ':refresh-thread', 0, raw: true, unless_exist: true, expires_in: 5.seconds) | |
| if Rails.cache.increment(name + ':refresh-thread') == 1 | |
| # we are the first visitor | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def custom_write_dogpile(name, timestamp, fragment, options) | |
| Rails.cache.write(timestamp_key(name, timestamp), fragment) | |
| Rails.cache.write(name + ':last', fragment) | |
| Rails.cache.delete(name + ':refresh-thread') | |
| fragment | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def custom_read_dogpile(name, timestamp, options) | |
| result = Rails.cache.read(timestamp_key(name, timestamp)) | |
| if result.blank? | |
| Rails.cache.write(name + ':refresh-thread', 0, raw: true, unless_exist: true, expires_in: 5.seconds) | |
| if Rails.cache.increment(name + ':refresh-thread') == 1 | |
| result = nil | |
| else | |
| result = Rails.cache.read(name + ':last') | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% custom_cache custom_cache_key('product-tile', @product.id), @product.updated_at, dogpile_protection: true do %> | |
| <%= @product.name %> | |
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sample::Application.configure do | |
| # Settings specified here will take precedence over those in config/application.rb. | |
| # In the development environment your application's code is reloaded on | |
| # every request. This slows down response time but is perfect for development | |
| # since you don't have to restart the web server when you make code changes. | |
| config.cache_classes = false | |
| # Do not eager load code on boot. | |
| config.eager_load = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sample::Application.configure do | |
| # Settings specified here will take precedence over those in config/application.rb. | |
| # Code is not reloaded between requests. | |
| config.cache_classes = true | |
| # Eager load code on boot. This eager loads most of Rails and | |
| # your application in memory, allowing both thread web servers | |
| # and those relying on copy on write to perform better. | |
| # Rake tasks automatically ignore this option for performance. |