我在 Ruby on Rails 应用程序中使用acts-as-taggable-on 来允许用户将标签添加到他们的联系人列表中(如带标签的地址簿)。添加/更新带有标签的联系人非常适合使用标准 RESTful 路径、、、contacts/new
等contacts/[:id]
的用户contacts/:id/edit
。
我现在正在尝试添加功能,以便用户可以向联系人发送电子邮件,要求他们确认并完成他们的详细信息。电子邮件请求包括一个链接到一个建立在不同控制器上的页面的链接,该控制器显示一个包含所有联系方式的表单(又名“确认表单”),减去标签(对用户来说是个人的)。
电子邮件链接的格式为:
contact_confirmation/[:id]/edit?contact_id=[:contact_id]
令牌在哪里[:id]
可以一次性访问联系人以更新他们的详细信息(这就像一个非常标准的密码重置)。
确认表单正确更新了所有联系方式,但由于某种原因,标签丢失了。两种情况下的params[]都是一样的,更新方法也是一样的。
查看日志,它们与第一个 COMMIT 相同。然后确认表单开始一个新进程(BEGIN)并删除标签:
(0.2ms) BEGIN
CACHE ActsAsTaggableOn::Tag Load (0.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL) [["taggable_id", 9], ["taggable_type", "Contact"]]
CACHE ActsAsTaggableOn::Tag Load (0.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL) [["taggable_id", 9], ["taggable_type", "Contact"]]
CACHE ActsAsTaggableOn::Tag Load (0.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND "taggings"."tagger_id" = $3 AND "taggings"."tagger_type" = $4 AND "taggings"."context" = $5 [["taggable_id", 9], ["taggable_type", "Contact"], ["tagger_id", 1], ["tagger_type", "User"], ["context", "tags"]]
ActsAsTaggableOn::Tagging Load (0.6ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND "taggings"."tagger_type" = $3 AND "taggings"."tagger_id" = $4 AND "taggings"."tag_id" IN (5, 43, 44) AND "taggings"."context" = $5 [["taggable_id", 9], ["taggable_type", "Contact"], ["tagger_type", "User"], ["tagger_id", 1], ["context", "tags"]]
SQL (0.5ms) DELETE FROM "taggings" WHERE "taggings"."id" = $1 [["id", 152]]
ActsAsTaggableOn::Tag Load (0.5ms) SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
SQL (0.8ms) UPDATE "tags" SET "taggings_count" = COALESCE("taggings_count", 0) - 1 WHERE "tags"."id" = $1 [["id", 5]]
ActsAsTaggableOn::Tag Load (1.3ms) SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
SQL (0.8ms) DELETE FROM "taggings" WHERE "taggings"."id" = $1 [["id", 153]]
ActsAsTaggableOn::Tag Load (0.4ms) SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT $2 [["id", 43], ["LIMIT", 1]]
SQL (0.5ms) UPDATE "tags" SET "taggings_count" = COALESCE("taggings_count", 0) - 1 WHERE "tags"."id" = $1 [["id", 43]]
ActsAsTaggableOn::Tag Load (0.4ms) SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT $2 [["id", 43], ["LIMIT", 1]]
ActsAsTaggableOn::Tagging Load (0.3ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."tag_id" = $1 [["tag_id", 43]]
SQL (0.5ms) DELETE FROM "tags" WHERE "tags"."id" = $1 [["id", 43]]
SQL (0.5ms) DELETE FROM "taggings" WHERE "taggings"."id" = $1 [["id", 154]]
ActsAsTaggableOn::Tag Load (0.4ms) SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT $2 [["id", 44], ["LIMIT", 1]]
SQL (0.9ms) UPDATE "tags" SET "taggings_count" = COALESCE("taggings_count", 0) - 1 WHERE "tags"."id" = $1 [["id", 44]]
ActsAsTaggableOn::Tag Load (0.4ms) SELECT "tags".* FROM "tags" WHERE "tags"."id" = $1 LIMIT $2 [["id", 44], ["LIMIT", 1]]
ActsAsTaggableOn::Tagging Load (0.5ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."tag_id" = $1 [["tag_id", 44]]
SQL (2.0ms) DELETE FROM "tags" WHERE "tags"."id" = $1 [["id", 44]]
ActsAsTaggableOn::Tag Load (3.1ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND "taggings"."tagger_id" = $3 AND "taggings"."tagger_type" = $4 AND "taggings"."context" = $5 [["taggable_id", 9], ["taggable_type", "Contact"], ["tagger_id", 1], ["tagger_type", "User"], ["context", "tags"]]
(1.2ms) COMMIT
谁能帮我弄清楚为什么会这样?谢谢。