OK、ここでは物事をシンプルに保ち、Rails コンソールでテストを行うようにしています。ただし、タグを保存して再度読み取る方法がわかりません。以下の貼り付けからわかるように、@consumer オブジェクトを (タグ付きで) 保存してからタグを読み取ることができません..
1.9.3p286 :001 > @consumer = Consumer.first
Creating scope :page. Overwriting existing method Consumer.page.
Consumer Load (1.3ms) SELECT "consumers".* FROM "consumers" LIMIT 1
=> #<Consumer id: 29, hl: nil, created_at: "2012-10-27 23:27:15", updated_at: "2012-10-27 23:27:15", user_id: 33, display_name: nil, tagline: nil, desc: nil>
1.9.3p286 :002 > @consumer.tags
ActsAsTaggableOn::Tag Load (2.3ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 29 AND "taggings"."taggable_type" = 'Consumer' AND (taggings.context = 'tags')
=> []
1.9.3p286 :003 > @consumer.tag_list
ActsAsTaggableOn::Tag Load (1.4ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 29 AND "taggings"."taggable_type" = 'Consumer' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
=> []
1.9.3p286 :004 > @consumer.tag_list = "hi, ho"
=> "hi, ho"
1.9.3p286 :005 > @consumer
=> #<Consumer id: 29, hl: nil, created_at: "2012-10-27 23:27:15", updated_at: "2012-10-27 23:27:15", user_id: 33, display_name: nil, tagline: nil, desc: nil>
1.9.3p286 :006 > @consumer.save
(0.4ms) BEGIN
(0.7ms) UPDATE "consumers" SET "updated_at" = '2013-02-15 00:25:05.187733' WHERE "consumers"."id" = 29
ActsAsTaggableOn::Tag Load (0.8ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'hi' OR lower(name) = 'ho')
ActsAsTaggableOn::Tag Exists (0.6ms) SELECT 1 AS one FROM "tags" WHERE "tags"."name" = 'hi' LIMIT 1
SQL (1.3ms) INSERT INTO "tags" ("name") VALUES ($1) RETURNING "id" [["name", "hi"]]
ActsAsTaggableOn::Tag Exists (0.5ms) SELECT 1 AS one FROM "tags" WHERE "tags"."name" = 'ho' LIMIT 1
SQL (0.4ms) INSERT INTO "tags" ("name") VALUES ($1) RETURNING "id" [["name", "ho"]]
ActsAsTaggableOn::Tag Load (0.7ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 29 AND "taggings"."taggable_type" = 'Consumer' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)
ActsAsTaggableOn::Tagging Exists (0.7ms) SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 5 AND "taggings"."taggable_type" = 'Consumer' AND "taggings"."taggable_id" = 29 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1
SQL (1.5ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["context", "tags"], ["created_at", Fri, 15 Feb 2013 00:25:05 UTC +00:00], ["tag_id", 5], ["taggable_id", 29], ["taggable_type", "Consumer"], ["tagger_id", nil], ["tagger_type", nil]]
ActsAsTaggableOn::Tagging Exists (0.7ms) SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 6 AND "taggings"."taggable_type" = 'Consumer' AND "taggings"."taggable_id" = 29 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1
SQL (0.5ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["context", "tags"], ["created_at", Fri, 15 Feb 2013 00:25:05 UTC +00:00], ["tag_id", 6], ["taggable_id", 29], ["taggable_type", "Consumer"], ["tagger_id", nil], ["tagger_type", nil]]
(11.9ms) COMMIT
=> true
1.9.3p286 :007 > Consumer.first.tags
Consumer Load (0.9ms) SELECT "consumers".* FROM "consumers" LIMIT 1
ActsAsTaggableOn::Tag Load (1.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 30 AND "taggings"."taggable_type" = 'Consumer' AND (taggings.context = 'tags')
=> []
また、DB のテーブルとしてタグまたはタグ付けが見つかりません。これを理解するのを手伝ってくれてありがとう。
編集:
問題があると思います..タグ付けテーブルで、id、tag_id、taggable_id、taggable_type、tagger_id、tagger_type、コンテキスト列が表示されています..行は、tagger_id と tagger_type を除いて完全に見えます。これは、タグが消費者の ID に関連付けられていないことと関係があると思いますか? 問題は、Consumer.id が実際にタグ付けテーブルのどこに表示されるかということだと思います..現時点では、Consumer.first.id はタグ付けのどの列にもありません! Consumer.first.id == 30