Skip to content

Instantly share code, notes, and snippets.

@datapimp
Created March 10, 2011 21:28
Show Gist options
  • Select an option

  • Save datapimp/864964 to your computer and use it in GitHub Desktop.

Select an option

Save datapimp/864964 to your computer and use it in GitHub Desktop.
class SectionsController < ApplicationController
before_filter :require_client
def index
cache_key = "#{ current_package.id }:sections"
@sections = Rails.cache.read cache_key
if !@sections
@sections = Section.tree_for( current_package )
Rails.cache.write cache_key, @sections
else
Rails.logger.info "Cache Hit on #{ cache_key }"
end
respond_to do |format|
format.json { render :json => jsonp_wrap(@sections) }
format.html { render :layout => false }
format.xml { render :xml => @sections }
end
end
def show
@section = current_package.sections.find( params[:id] )
respond_to do |format|
format.json { render :json => jsonp_wrap(@section) }
format.html { render :layout => false }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment