Created
November 29, 2018 12:28
-
-
Save tbuehlmann/edbcea1f4719cf0d28b236e3d1b372af 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 BaseAuditsController < ApplicationController | |
def self.inherited(other) | |
other.class_eval do | |
resource_name = controller_path.split('/').first.singularize | |
define_method("set_#{resource_name}") do | |
resource = organization.public_send(resource_name.pluralize).find(params["#{resource_name}_id"]) | |
instance_variable_set("@#{resource_name}", resource) | |
end | |
before_action :"set_#{resource_name}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment