Search code examples
ruby-on-railsrubyruby-on-rails-4acts-as-taggable-onacts-as-taggable

make acts-as-taggable gem case-sensitive


I am using the acts as tag gable gem and it is forcing some tags with capital letters to be all lowercase. For example, when i try to add 'Computer Science', it adds 'computer science' instead and the server logs show this:

  ActsAsTaggableOn::Tag Load (0.6ms)  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", 12], ["taggable_type", "Project"]]
   => ["computer science", "Computer Science"]

I do not want this. The actsastaggable github page says to add this:

ActsAsTaggableOn.strict_case_match = true

I have added that line to the application.rb file but it is still not working. How do I make actsastaggable case-sensitive?


Solution

  • I have tested this and it works for me. Make sure you don't have the following written in your application.rb:

    ActsAsTaggableOn.force_lowercase = true
    

    If that doesn't solve it add more info.

    Having said that, you might want to consider keeping your Tags lowercase for two reasons:

    1.) clean URL's - you want to avoid upper case letters in your URL. They are not case sensitive but it's simply pretty. If people other than yourself are allowed to tag they could come up with string such as "hEll0PeEpS" and that you don't want in clean URL's, right?

    2.) Have control over your design. This relates to the first point I made - if someone uses fancy tags using upper/lowercase randomly it will be written like this wherever you list your tags.

    Save them lowercase instead and use .capitalize

    However, if you requirements are different and require free choice of upper and lowercase letters then disregard my additional thoughts :)