0

我正在使用actsastaggableon gem。出於某種原因,系統將標籤「Python」保存爲「python(小寫)」。由於我驗證用戶只能輸入特定的標籤,系統將標籤保存爲「python」會導致一些問題。以下是我的服務器日誌。第一行是在所有驗證運行(它通過)之後tag_list的puts語句。之後,服務器正在做一些奇怪的事情,並將「Python」變成「python」。這可能與緩存有關,因爲我曾經有一個名爲「python」的標籤,但我不再這樣做。如何解決這個問題,而不會嚴重改變我的緩存設置?acts_As_taggabe_on更改標籤大小寫 - 可能緩存問題但不確定

["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

你有沒有設置這個地方:

ActsAsTaggableOn.force_lowercase = true 

如果從而迫使小寫

如果你沒有這樣的設置,可以是另一個可能的問題,如果你正在使用MySQL的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