I'm having User model (within PostgreSQL database) in my RoR application that's using Devise for authentication. Now I want users to be invited, so I decided to use devise_invitable gem. Following the installation guide I did:
- Add gem 'devise_invitable' to my Gemfile
- Run rails generate devise_invitable:install
- Run rails generate devise_invitable User
Than I tried to run the migration, generated above (it is the default one given by this gem and it looks like:)
class DeviseInvitableAddToUsers < ActiveRecord::Migration
def up
change_table :users do |t|
t.string :invitation_token, :limit => 60
t.datetime :invitation_sent_at
t.datetime :invitation_accepted_at
t.integer :invitation_limit
t.references :invited_by, :polymorphic => true
t.index :invitation_token, :unique => true # for invitable
t.index :invited_by_id
end
# And allow null encrypted_password and password_salt:
change_column_null :users, :encrypted_password, true
end
def down
change_table :users do |t|
t.remove_references :invited_by, :polymorphic => true
t.remove :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token
end
end
end
But, while running migrations, I get:
== DeviseInvitableAddToUsers: migrating ======================================
-- change_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:
PG::Error: ERROR: relation "invited_bies" does not exist
: ALTER TABLE "users" ADD CONSTRAINT fk_users_invited_by_id FOREIGN KEY ("invited_by_id") REFERENCES "invited_bies" ("id")
I am not guru in PostgreSQL and it's foreign keys, but it looks like there should be invited_bies table, should not it? But it is not being created. So, I'm a bit puzzled with this all.
My User model for devise:
devise :invitable, :database_authenticatable, :recoverable, :rememberable, token_authenticatable,:trackable, :authentication_keys => [:email]
The fields :invitable, :database_authenticatable
were added by the generating script.