Skip to content

Instantly share code, notes, and snippets.

@brenes
Last active February 14, 2024 11:39
Show Gist options
  • Save brenes/4503386 to your computer and use it in GitHub Desktop.
Save brenes/4503386 to your computer and use it in GitHub Desktop.

Revisions

  1. brenes revised this gist Sep 10, 2015. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions model_extension_rails_4.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # We have to remove validations on email, as it's no longer needed.
    # Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
    Model.class_eval do
    _validators.delete(:template)

    _validate_callbacks.each do |callback|
    if callback.raw_filter.respond_to? :attributes
    callback.raw_filter.attributes.delete :template
    end
    end
    end
  2. brenes created this gist Jan 10, 2013.
    15 changes: 15 additions & 0 deletions model_extension.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # We have to remove validations on email, as it's no longer needed.
    # Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
    Model.class_eval do
    _validators.reject!{ |key, _| key == :field }


    _validate_callbacks.each do |callback|
    callback.raw_filter.attributes.delete :field
    end

    _validate_callbacks.reject! do |callback|
    callback.raw_filter.attributes.empty? || callback.raw_filter.attributes == [:field]
    end

    end