You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have kind of a strange requirement, but it makes sense for the client: tag names have to be case sensitive and a tag named Ruby is not the same as ruby.
So here's what I did:
# config/initializers/gutentag.rb# don't normalise tag namesGutentag.normaliser=lambda{ |name| name}# overwrite validations, so uniqueness is not case insensitive as it is the defaultclassTagValidationsdefself.call(klass)new(klass).callenddefinitialize(klass)@klass=klassenddefcallklass.validates:name,presence: true,uniqueness: true,length: {maximum: 255}endprivateattr_reader:klassendGutentag.tag_validations=TagValidations
Which works fine to a certain point, but there's a nuance in MySQL. Depending on the collation of the field (which often is utf8_general_ci, which is a default in many MySQL setups I have seen), the index might be case sensitive or not. If you set a unique index, like we do at
classChangeCollationOfGutentagTags < ActiveRecord::Migration[5.2]defupexecute"ALTER TABLE `gutentag_tags` CONVERT TO CHARACTER SET UTF8 COLLATE utf8_bin"enddefdownexecute"ALTER TABLE `gutentag_tags` CONVERT TO CHARACTER SET UTF8 COLLATE utf8_general_ci"endend
and it now works like a charm :)
I don't know if Gutentag can do anything about this (unlikely), but at least this is documented somewhere now :)
The text was updated successfully, but these errors were encountered:
Hey there,
I have kind of a strange requirement, but it makes sense for the client: tag names have to be case sensitive and a tag named
Ruby
is not the same asruby
.So here's what I did:
Which works fine to a certain point, but there's a nuance in MySQL. Depending on the collation of the field (which often is
utf8_general_ci
, which is a default in many MySQL setups I have seen), the index might be case sensitive or not. If you set a unique index, like we do atgutentag/db/migrate/1_gutentag_tables.rb
Line 24 in 0557645
ruby
andRuby
will be the same and therefore will throw an error.To get it working, you have to change the collation to something that is case sensitive in MySQL (there's a whole bunch of docs about that here https://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html).
In my case, I wrote this migration:
and it now works like a charm :)
I don't know if Gutentag can do anything about this (unlikely), but at least this is documented somewhere now :)
The text was updated successfully, but these errors were encountered: