Thursday, November 29, 2007

Put This In Your ApplicationController And Smoke It

def instance(conditions = :all)
  i_var = instance_variable_get "@#{model_name.pluralize}"
  i_var = model_name.camelize.constantize.find(conditions)
end

before_filter :instance


The idea comes from Dan Yoder.


Update: I am a crackhead. That should use ivar_set, not _get.