Skip to content

Instantly share code, notes, and snippets.

@rajivm
Created April 22, 2015 18:49
Show Gist options
  • Select an option

  • Save rajivm/b4d318c73f574e559080 to your computer and use it in GitHub Desktop.

Select an option

Save rajivm/b4d318c73f574e559080 to your computer and use it in GitHub Desktop.

Revisions

  1. rajivm created this gist Apr 22, 2015.
    18 changes: 18 additions & 0 deletions soft_forbidden_attrs.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    module ActiveModel
    class ForbiddenAttributes < StandardError
    end

    module SoftForbiddenAttributesProtection
    def sanitize_for_mass_assignment(*options)
    new_attributes = options.first
    if !new_attributes.respond_to?(:permitted?) || new_attributes.permitted?
    super
    elsif Rails.env.production?
    logger.error("ActiveModel::ForbiddenAttributes")
    super
    else
    raise ActiveModel::ForbiddenAttributes
    end
    end
    end
    end