我使用的是Rails 4.1.14,Ruby 2.1.6,Devise 3.2.4和Devise_invitable 1.3.6。
我遇到的问题是,一旦我邀请的新用户按下他们收到的电子邮件中的接受邀请链接,它就会陷入重定向循环。我无法弄清楚原因。
这些是整个操作的服务器日志(请注意,日志的第一部分的大部分对应于我在下面省略的逻辑 - 但我留下它以防万一它有趣):
Started GET "/users/invitation/accept?invitation_token=qANzitr64dxzxG9dSsMU" for 127.0.0.1 at 2015-12-12 04:51:29 -0500
Processing by Users::InvitationsController#edit as HTML
Parameters: {"invitation_token"=>"qANzitr6"}
User Load (4.0ms) SELECT "users".* FROM "users" WHERE "users"."invitation_token" = 'qANzitr6' ORDER BY "users"."id" ASC LIMIT 1
User Load (1.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Member Load (3.8ms) SELECT "members".* FROM "members" WHERE "members"."email" = 'def@test.com' LIMIT 1
Membership Load (88.3ms) SELECT "memberships".* FROM "memberships" WHERE "memberships"."member_id" = 115 LIMIT 1
Connection Load (14.8ms) SELECT "connections".* FROM "connections" WHERE "connections"."membership_id" = 173 ORDER BY "connections"."id" ASC LIMIT 1
(2.3ms) BEGIN
SQL (3.4ms) UPDATE "memberships" SET "invited_id" = $1, "member_id" = $2, "relative_type" = $3, "updated_at" = $4 WHERE "memberships"."id" = 173 [["invited_id", 83], ["member_id", nil], ["relative_type", 1], ["updated_at", "2015-12-12 09:51:30.038439"]]
(1.8ms) COMMIT
Membership Load (2.3ms) SELECT "memberships".* FROM "memberships" WHERE "memberships"."user_id" = $1 AND "memberships"."invited_id" = 83 ORDER BY "memberships"."id" ASC LIMIT 1 [["user_id", 1]]
FamilyTree Load (1.7ms) SELECT "family_trees".* FROM "family_trees" WHERE "family_trees"."user_id" = $1 LIMIT 1 [["user_id", 83]]
Membership Load (3.7ms) SELECT "memberships".* FROM "memberships" WHERE "memberships"."user_id" = 83 AND "memberships"."invited_id" = 1 AND "memberships"."family_tree_id" = 85 AND "memberships"."relation" = 'wife' AND "memberships"."relative_type" = 1 LIMIT 1
(33.0ms) BEGIN
SQL (37.9ms) INSERT INTO "memberships" ("created_at", "family_tree_id", "invited_id", "relation", "relative_type", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["created_at", "2015-12-12 09:51:30.105734"], ["family_tree_id", 85], ["invited_id", 1], ["relation", "wife"], ["relative_type", 1], ["updated_at", "2015-12-12 09:51:30.105734"], ["user_id", 83]]
Connection Exists (11.7ms) SELECT 1 AS one FROM "connections" INNER JOIN "memberships" ON "memberships"."id" = "connections"."membership_id" WHERE (memberships.invited_id = 83) LIMIT 1
(2.1ms) COMMIT
(1.6ms) BEGIN
SQL (3.7ms) UPDATE "connections" SET "invited_membership_id" = $1, "invited_user_id" = $2, "request_status" = $3, "responded_at" = $4, "updated_at" = $5 WHERE "connections"."id" = 127 [["invited_membership_id", 174], ["invited_user_id", 83], ["request_status", 1], ["responded_at", "2015-12-12 09:51:30.167563"], ["updated_at", "2015-12-12 09:51:30.172215"]]
(1.9ms) COMMIT
SQL (2.3ms) DELETE FROM "members" WHERE "members"."id" = 115
Rendered shared/_footer.html.erb (4.5ms)
Rendered users/invitations/edit.html.erb within layouts/devise (48.6ms)
Completed 200 OK in 1689ms (Views: 1405.9ms | ActiveRecord: 222.2ms)
Started PUT "/users/invitation" for 127.0.0.1 at 2015-12-12 04:51:53 -0500
Processing by UsersController#update as HTML
Parameters: {"utf8"=>"✓", "user"=>{"invitation_token"=>"qANzitr6", "gender"=>"female", "invitation_relation"=>"wife", "full_name"=>"My Wife", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Register", "id"=>"invitation"}
Completed 401 Unauthorized in 8ms (ActiveRecord: 0.0ms)
Started GET "/users/login" for 127.0.0.1 at 2015-12-12 04:51:53 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"login"}
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
Started GET "/users/login" for 127.0.0.1 at 2015-12-12 04:51:53 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"login"}
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
这是我的Users::InvitationsController#Edit
def edit
# Some logic that I know works and is irrelevant to this question.
# below is lifted directly from the `edit` action within the gem itself.
set_minimum_password_length if respond_to? :set_minimum_password_length
resource.invitation_token = params[:invitation_token]
render :edit
end
然后我指定了一个accept_resource
方法,如the docs建议,如果我希望在发送邀请之后或之前发生任何特殊情况,我会这样做。
def accept_resource
resource = resource_class.accept_invitation!(update_resource_params)
resource.confirm!
resource
end
我认为必须发生的部分原因是我陷入了一个循环,用户的帐户在他们接受之后未被确认....因此覆盖。
这是我的User.rb
:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :invitable, :confirmable
end
导致这种情况的原因是什么?