Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

simplified association naming for 'verifiable_for' associations; 1st …

…solution was more complex than it needed to be (we didn't need lots of unique names, we just needed _a different name_)
latest commit 6174dc2b0c
Charlie Hornberger authored



Creates verified associations. Verified associations are similar to regular associations, except that a step has been taken to verify the integrity of the association.


Add verifiable to your Gemfile (or whatever if you're not using bundler):

gem "verifiable"

Run the generator to create the necessary database migration and run it:

script/generate verifiable_migration
rake db:migrate

Include Verifiable::Associations in your classes and specify the correct type of association:

class User < ActiveRecord::Base

  include Verifiable::Associations
  has_many_verifiable :phone_numbers


class PhoneNumber < ActiveRecord::Base

  include Verifiable::Associations
  verifiable_for :users


Create some associations that need verification:

user = User.create
phone_number = user.phone_numbers.create

Associated objects don't show up until they're verified:

>> user.phone_numbers == []
=> true

Get unverified objects like this:

>> user.unverified_phone_numbers == [phone_number]
=> true

Get the verification code for an association (code is a random 4 digit string):

code = user.verification_code_for(phone_number)

Verify the association (returns true if code is correct):

user.verify!(phone_number, code)

Once verified, the associated objects show up:

>> user.phone_numbers == [phone_number]
=> true

To create a verification that has a different type of code:

user = User.create
phone_number = PhoneNumber.create
Verifiable::Verification.create(:code => "abcd", :object => user, :verifiable => phone_number)


The MIT License, see LICENSE


  • Make singular associations work (has_one)

  • Figure out a way to make association specific verification code generators

Something went wrong with that request. Please try again.