Skip to content

Instantly share code, notes, and snippets.

@scomma
Created March 30, 2013 10:59
Show Gist options
  • Save scomma/5276319 to your computer and use it in GitHub Desktop.
Save scomma/5276319 to your computer and use it in GitHub Desktop.
Page-caching thoughtbot's excellent high_voltage
class TemplatesController < HighVoltage::PagesController
caches_page except: []
skip_before_filter :authenticate_user!
layout false
end
class ThingsController < ApplicationController
before_filter :render_template
def index
# ...
end
def show
# ...
end
private
def render_template
render 'templates/things' unless params[:format] == 'json'
true
end
end
@scomma
Copy link
Author

scomma commented Mar 30, 2013

A bit of background.

So we ported our Rails app to angular.js recently and I was trying to decide where the template files should go. Their respective controllers' views/? Doesn't fit, now that the 1:1 action/template mapping no longer holds. The public folder? Nice, except I still rely on erb snippets to generate js/css dependencies.

high_voltage seems like a good middleground. The templates are relatively static and isolated from the views, and you can still write view logic. The best part is you can page-cache them so the compiled versions land straight in public/, to be served by nginx/apache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment