ruby on rails - acts_As_taggabe_on更改标签的情况-可能缓存问题,但不确定



我使用的是actsastaggableon宝石。由于某些原因,系统将标签"Python"保存为"Python(小写)"。由于我正在验证用户只能输入某些标签,因此系统将标签保存为"python"会导致一些问题。下面是我的服务器日志。第一行是运行完所有验证后tag_list的put语句(它通过了)。然后,服务器做了一些奇怪的事情,把"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"]]

你把这个设置在什么地方了吗?

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

相关内容

  • 没有找到相关文章

最新更新