Skip to content

Instantly share code, notes, and snippets.

@brand-it
Created March 26, 2012 21:57
Show Gist options
  • Save brand-it/2210076 to your computer and use it in GitHub Desktop.
Save brand-it/2210076 to your computer and use it in GitHub Desktop.
A nice way to send session data to the active recored.
class ApplicationController < ActionController::Base
# Your existing stuff
around_filter :you_dont_have_bloody_clue
protected
def you_dont_have_bloody_clue
klasses = [ActiveRecord::Base, ActiveRecord::Base.class]
methods = ["session", "cookies", "params", "request"]
methods.each do |shenanigan|
oops = instance_variable_get(:"@_#{shenanigan}")
klasses.each do |klass|
klass.send(:define_method, shenanigan, proc { oops })
end
end
yield
methods.each do |shenanigan|
klasses.each do |klass|
klass.send :remove_method, shenanigan
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment