Skip to content

Instantly share code, notes, and snippets.

@0xSventek
Created October 4, 2011 00:38
Show Gist options
  • Save 0xSventek/1260639 to your computer and use it in GitHub Desktop.
Save 0xSventek/1260639 to your computer and use it in GitHub Desktop.
projects_controller
class ProjectsController < ApplicationController
before_filter :get_base_project, :only => [:next,:previous]
before_filter :force_js_content_type, :only => [:next,:previous]
caches_action :next, :cache_path => proc{ |c| "/projects/" + (c.get_base_project.next.cache_key rescue "nil")}, :expires_in => 15.minutes
caches_action :previous, :cache_path => proc{ |c| "/projects/" + (c.get_base_project.previous.cache_key rescue "nil")}, :expires_in => 15.minutes
def next
@project = @base_project.next
render :switch_project
end
def previous
@project = @base_project.previous
render :switch_project
end
protected
def get_base_project
@base_project = Period.find(params[:base_project_id])
end
def force_js_content_type
response.headers["Content-Type"] = "text/javascript"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment