Skip to content

Instantly share code, notes, and snippets.

@kamarcum
Created November 19, 2012 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamarcum/4111568 to your computer and use it in GitHub Desktop.
Save kamarcum/4111568 to your computer and use it in GitHub Desktop.
A probably incorrect live-coded eTag example that doesn't use the eTag middleware
class StudentController < ApplicationController
def show
existing_etag = request.headers["if-none-match"]
student = Student.where(id: params[:id]).first
if(existing_etag)
type, id, modified = existing_etag.split("_")
if(type == student && id == params[:id])
if(student.updated_at == modified)
render :not_modified and return
end
end
else
response.headers["eTag"] = "student_#{params[:id]}_#{student.updated_at}"
render student
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment