Created
April 14, 2014 00:30
-
-
Save kaievns/10608078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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