Skip to content

Instantly share code, notes, and snippets.

@kaievns
Created April 14, 2014 00:30
Show Gist options
  • Save kaievns/10608078 to your computer and use it in GitHub Desktop.
Save kaievns/10608078 to your computer and use it in GitHub Desktop.
class ApplicationController
before_fitler :autfind_stuff
def self.autofinders
@autofinders ||= []
end
def self.autofind(param, &block)
autofinders << [param, block]
end
def autofind_stuff
ApplicationController.autofinders.each do |param, block|
if params.has_key?(param)
instance_exec params[param], &block
end
end
end
autofind :user_id do |user_id|
@user = User.find(user_id)
end
autofind :commend_id do |comment_id|
@comment = Comment.find(comment_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment