我正在使用actsastaggableon gem。出于某种原因,系统将标签“Python”保存为“python(小写)”。由于我验证用户只能输入某些标签,因此系统将标签保存为“python”会导致一些问题。以下是我的服务器日志。在所有验证运行(通过)之后,第一行是tag_list的puts语句。然后,服务器正在做一些奇怪的事情并将“Python”变为“python”。这可能与缓存有关,因为我曾经有一个名为“python”的标签,但我不再这样做了。如何在不严重更改缓存设置的情况下解决此问题?
["IOS | IPhone | IPad", "App and Web development", "PHP", "Rails", "Python"]
ActsAsTaggableOn::Tag Load (0.8ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'ios | iphone | ipad' OR lower(name) = 'app and web development' OR lower(name) = 'php' OR lower(name) = 'rails' OR lower(name) = 'python')
ActsAsTaggableOn::Tag Load (0.8ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'ios | iphone | ipad' OR lower(name) = 'app and web development' OR lower(name) = 'php' OR lower(name) = 'rails' OR lower(name) = 'python')
CACHE (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", 16], ["taggable_type", "Profile"]]
CACHE (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", 16], ["taggable_type", "Profile"]]
ActsAsTaggableOn::Tagging Exists (0.6ms) SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 1 AND "taggings"."taggable_type" = 'Profile' AND "taggings"."taggable_id" = 16 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1
ActsAsTaggableOn::Tagging Exists (0.6ms) SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 1 AND "taggings"."taggable_type" = 'Profile' AND "taggings"."taggable_id" = 16 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1
SQL (3.8ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["context", "tags"], ["created_at", Tue, 25 Mar 2014 16:05:41 EDT -04:00], ["tag_id", 1], ["taggable_id", 16], ["taggable_type", "Profile"]]
SQL (3.8ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["context", "tags"], ["created_at", Tue, 25 Mar 2014 16:05:41 EDT -04:00], ["tag_id", 1], ["taggable_id", 16], ["taggable_type", "Profile"]]
答案 0 :(得分:0)
你有没有把它设置在某个地方:
ActsAsTaggableOn.force_lowercase = true
如果是这样,那就是强制小写
如果您没有该设置,如果您使用mysql for db可能会遇到另一个可能的问题: https://github.com/mbleigh/acts-as-taggable-on/issues/259
class EditTagTableToBeCaseSensitive < ActiveRecord::Migration
def up
@sql = "ALTER TABLE `tags` CHANGE `name` `name` VARCHAR(255) BINARY DEFAULT NULL;"
execute @sql
end
def down
@sql = "ALTER TABLE `tags` CHANGE `name` `name` VARCHAR(255) DEFAULT NULL;"
execute @sql
end
end