Skip to content

Instantly share code, notes, and snippets.

@Exact1990
Created February 15, 2016 14:15
Show Gist options
  • Select an option

  • Save Exact1990/6c5b346a7138c3eebe9f to your computer and use it in GitHub Desktop.

Select an option

Save Exact1990/6c5b346a7138c3eebe9f to your computer and use it in GitHub Desktop.
module ApplicationType
extend ActiveSupport::Concern
module ClassMethods
def model_name
superclass.model_name
end
def name
superclass.name
end
def permit(*args)
@_args ||= []
@_args.concat(args)
end
def _args
@_args
end
def descendants
superclass.descendants
end
def new(*args, &block)
attrs = ActionController::Parameters.new(args.first)
permitted_attrs = attrs.send :permit, self._args
args[0] = permitted_attrs
super
end
end
def assign_attributes(attrs = {})
attrs = ActionController::Parameters.new(attrs) unless attrs.is_a?(ActionController::Parameters)
permitted_attrs = attrs.send :permit, self.class._args
super(permitted_attrs)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment