Skip to content

Instantly share code, notes, and snippets.

@epintos
Created January 14, 2016 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epintos/336cd7fed90992a863e6 to your computer and use it in GitHub Desktop.
Save epintos/336cd7fed90992a863e6 to your computer and use it in GitHub Desktop.
Document with token validator
class Document < ActiveRecord::Base
include UniqueTokenValidator
UNIQUE_FIELDS = {
key: :name,
scope: [:description, :date],
condition: proc { |obj| some_method(obj) }
}
validates UNIQUE_FIELDS[:key], uniqueness: {
scope: UNIQUE_FIELDS[:scope]
}, if: UNIQUE_FIELDS[:condition]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment