Skip to content

Instantly share code, notes, and snippets.

@Exact1990
Created February 15, 2016 14:15
Show Gist options
  • Save Exact1990/6c5b346a7138c3eebe9f to your computer and use it in GitHub Desktop.
Save Exact1990/6c5b346a7138c3eebe9f to your computer and use it in GitHub Desktop.

Revisions

  1. Nikolay Zykov created this gist Feb 15, 2016.
    40 changes: 40 additions & 0 deletions gistfile1.txt
    Original 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