acts_As_taggabe_on changing case of tags - possibly caching issue but not sure

114 Views Asked by At

I am using the actsastaggableon gem. For some reason, the system is saving the tag "Python" as "python (lowercase)". Since i am validating that users can only enter certain tags, the system saving the tag as "python" is causing some problems. Below are my server logs. The first line is a puts statement of the tag_list after all the validations have run (it passes). Then after that the server is doing something strange and turning "Python" to "python". This may have something to do with caching as I used to have a tag called "python" but I no longer do. How do I fix this without seriously changing my cache settings?

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

There are 1 best solutions below

0
emcanes On

Have you set this somewhere:

ActsAsTaggableOn.force_lowercase = true

If so that is forcing lowercase

If you don't have that set, another possible problem can be if you are using mysql for db that can be found here: 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