Skip to content

Instantly share code, notes, and snippets.

@jcasimir
Created April 22, 2011 20:49
Show Gist options
  • Save jcasimir/937595 to your computer and use it in GitHub Desktop.
Save jcasimir/937595 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :lookup, :only => [:show, :destroy, :edit, :update]
def lookup
class_name = params[:controller].singularize
klass = class_name.camelize.constantize
self.instance_variable_set "@" + class_name, klass.find(params[:id])
end
end
@webandy
Copy link

webandy commented Apr 23, 2011

Interesting, definitely a common pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment