Created
February 15, 2016 14:15
-
-
Save Exact1990/6c5b346a7138c3eebe9f to your computer and use it in GitHub Desktop.
Revisions
-
Nikolay Zykov created this gist
Feb 15, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ 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