Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Created November 29, 2018 12:28
Show Gist options
  • Save tbuehlmann/edbcea1f4719cf0d28b236e3d1b372af to your computer and use it in GitHub Desktop.
Save tbuehlmann/edbcea1f4719cf0d28b236e3d1b372af to your computer and use it in GitHub Desktop.
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