Sha256: 1cc916dd7f14f4d914c45c6fbd12af1035ddc3661dea7e19dddc2cad1f1fbd4e

Contents?: true

Size: 753 Bytes

Versions: 3

Compression:

Stored size: 753 Bytes

Contents

# frozen_string_literal: true

class User < ActiveRecord::Base
  include DeviseTokenAuth::Concerns::User

  validates :operating_thetan, numericality: true, allow_nil: true
  validate :ensure_correct_favorite_color

  def ensure_correct_favorite_color

    if favorite_color && (favorite_color != '')
      unless ApplicationHelper::COLOR_NAMES.any?{ |s| s.casecmp(favorite_color)==0 }
        matches = ApplicationHelper::COLOR_SEARCH.search(favorite_color)
        closest_match = matches.last[:string]
        second_closest_match = matches[-2][:string]
        errors.add(:favorite_color, "We've never heard of the color \"#{favorite_color}\". Did you mean \"#{closest_match}\"? Or perhaps \"#{second_closest_match}\"?")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
devise_token_auth-1.0.0 test/dummy/app/models/user.rb
devise_token_auth-1.0.0.rc2 test/dummy/app/models/user.rb
devise_token_auth-1.0.0.rc1 test/dummy/app/models/user.rb