Skip to content

Instantly share code, notes, and snippets.

@debajit
debajit / models_controller.rb
Created July 25, 2015 00:45
Cache render JSON in a Rails controller
def show
if stale?(@model, public: true)
respond_to do |format|
format.json do
full_structure_json = Rails.cache.fetch("#{@model.cache_key}") do
MyCustomSerializer.new(@model).to_json
end
render json: full_structure_json
end
@debajit
debajit / Updater.rb
Created August 27, 2015 01:15
Call method when defining Ruby constant
class Updater
METADATA_FILE = self.class.file_path
def initialize
METADATA_FILE
end
def self.file_path
'some file path'
end

Keybase proof

I hereby claim:

  • I am debajit on github.
  • I am debajit (https://keybase.io/debajit) on keybase.
  • I have a public key ASAUVr0SOg_-qoSNlPSZ0yzgOtWHVkVuRc331-IlryTxLwo

To claim this, I am signing this object: