Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tags with same name / one lowercase #661

Open
keyranova opened this issue Jun 17, 2015 · 3 comments
Open

tags with same name / one lowercase #661

keyranova opened this issue Jun 17, 2015 · 3 comments

Comments

@keyranova
Copy link

acts_as_taggable_on: 3.4 gem
rails: 4.2.2

I'm currently coding a cms with tagging and although autocomplete is added and working for tags, someone managed to duplicate a tag with lowercase instead of uppercase.

While the current tag "Branding" returned around 72 results, the newly added tag "branding" caused both tagged_with queries to return 0 results. Any possible validation to not allow an already available tag with just a different case?

@alexcp
Copy link

alexcp commented Jul 10, 2015

You can set the option ActsAsTaggableOn.force_lowercase = true in config/initializers/acts_as_taggable_on.rb to ensure tags are saved in lowercase.

@starspace1
Copy link

The solution above works for preventing that problem in the future. Is there anything built in to deal with existing duplicates? It's not possible to rename the first "Branding" tag as "branding" without first removing the "branding" tag.

@Ricardonacif
Copy link

@starspace1 I had to create a class to clean them up. Basically calling both methods on the tag with upcase chars:

class TagCleaner
  class << self

    def transfer_taggings_associations_and_delete from_tag, to_tag
      from_tag.taggings.find_each do |tagging|
        to_tag.taggings << tagging.dup
      end
      from_tag.destroy
    end

    def find_or_create_lowercase_related_tag tag
      lowercase_tag = ActsAsTaggableOn::Tag.find_or_create_by(name: tag.name.downcase)
    end
  end

end

kikito added a commit to AyuntamientoMadrid/consul that referenced this issue Apr 6, 2017
Problem is that we have some duplicated tags in production with
uppercase and lowercase (e.g. "Medios" and "medios"). The gem expects
them to be all lowercase. And as such, some methods of the gem fail
(`Proposal.tagged_with('Medios')` returns 0 results). So I have
implemented my own thing using activerecord relationships.

Reference issue in acts_as_taggable_on:
mbleigh/acts-as-taggable-on#661
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants