Created
March 30, 2013 10:59
-
-
Save scomma/5276319 to your computer and use it in GitHub Desktop.
Page-caching thoughtbot's excellent high_voltage
This file contains 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 TemplatesController < HighVoltage::PagesController | |
caches_page except: [] | |
skip_before_filter :authenticate_user! | |
layout false | |
end |
This file contains 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 inpublic/
, to be served by nginx/apache.