認証にDeviseを使用しているRoRアプリケーションにユーザーモデル(PostgreSQLデータベース内)があります。ユーザーを招待したいので、devise_invitable gem を使用することにしました。私が行ったインストールガイドに従って:
- Gemfile に gem 'devise_invitable' を追加
- rails generate devise_invitable:install を実行します
- rails generate devise_invitable ユーザーを実行します
上記で生成された移行を実行しようとしたよりも (これは、この gem によって指定されたデフォルトのものであり、次のようになります:)
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
しかし、移行の実行中に次のようになります。
== 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")
私は PostgreSQL の第一人者ではなく、それは外部キーですが、inviteted_bies テーブルがあるはずですよね? しかし、それは作成されていません。だから、私はこれに少し困惑しています。
デバイスの私のユーザーモデル:
devise :invitable, :database_authenticatable, :recoverable, :rememberable, token_authenticatable,:trackable, :authentication_keys => [:email]
フィールド:invitable, :database_authenticatable
は生成スクリプトによって追加されました。