Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Validations in Ruby

Validations in Ruby

Krzysztof Wawer

March 23, 2016
Tweet

More Decks by Krzysztof Wawer

Other Decks in Programming

Transcript

  1. ACTIVE MODEL V ALIDATIONS • acceptance • confirmation • exclusion

    • format • inclusion • length • numericality • presence • uniqueness*
  2. UNIQUENESS V ALIDATION tester@example.com exists ? tester@example.com exists ? Email

    doesn’t exist Email doesn’t exist Create tester@example.com Create tester@example.com Created! Created! 1 2
  3. UNIQUENESS V ALIDATION tester@example.com exists ? tester@example.com exists ? Email

    doesn’t exist Email doesn’t exist Create tester@example.com Create tester@example.com Created! ActiveRecord::RecordNotUnique 1 2
  4. STRONG PARAMETERS { name: „John”, surname: „Doe” } ActionController::UnpermittedParameters: found

    unpermitted keys: surname ActionController::Parameters.action_on_unpermitted_parameters = :raise
  5. HANAMI-V ALIDATIONS • numericality V ALIDATION DoesN’t Exist • „The

    framework will treat as V alid any blank attributes, without PRESENCE, for both FORMAT and SIZE predicates.”
  6. DRY-V ALIDATION When to use? V ALIDATION OF: • form

    params • „GET” params • JSON params • Y AML DOCUMENTS • application configuration • replacement of ActiveRecord / ActiveModel::Validations • replacement of StrongParameters • …
  7. ???