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 [email protected] exists ? [email protected] exists ? Email

    doesn’t exist Email doesn’t exist Create [email protected] Create [email protected] Created! ActiveRecord::RecordNotUnique 1 2
  3. STRONG PARAMETERS { name: „John”, surname: „Doe” } ActionController::UnpermittedParameters: found

    unpermitted keys: surname ActionController::Parameters.action_on_unpermitted_parameters = :raise
  4. 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.”
  5. 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 • …
  6. ???