Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Latin Characters #269

Closed
wants to merge 1 commit into from

3 participants

@Ricardonacif

Hello,

I had a problem using this gem and Mysql. When I had a tag named "historia" and another named "história", if I tagged an object with "historia" and searched it, I was getting both "historia" and "história". So I solved it.

Please tell me if there is something wrong with my pull request.

Cheers,

@caueguerra

hey @Ricardonacif,

I don't think that your pull request is necessary. If you just change the collation on the name column in the tags table to utf8_bin it works out of the box

@artemk artemk closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
10 lib/acts_as_taggable_on/tag.rb
@@ -21,17 +21,17 @@ def self.named(name)
end
def self.named_any(list)
- where(list.map { |tag| sanitize_sql(["lower(name) = ?", tag.to_s.mb_chars.downcase]) }.join(" OR "))
- end
-
- def self.named_like(name)
- where(["name #{like_operator} ? ESCAPE '!'", "%#{escape_like(name)}%"])
+ where(list.map { |tag| sanitize_sql(["lower(name) = #{using_mysql? ? 'BINARY(?)' : '?' }", tag.to_s.mb_chars.downcase]) }.join(" OR "))
end
def self.named_like_any(list)
where(list.map { |tag| sanitize_sql(["name #{like_operator} ? ESCAPE '!'", "%#{escape_like(tag.to_s)}%"]) }.join(" OR "))
end
+ def self.named_like(name)
+ where(["name #{like_operator} ? ESCAPE '!'", "%#{escape_like(name)}%"])
+ end
+
### CLASS METHODS:
def self.find_or_create_with_like_by_name(name)
View
4 lib/acts_as_taggable_on/utils.rb
@@ -15,6 +15,10 @@ def using_sqlite?
::ActiveRecord::Base.connection && ::ActiveRecord::Base.connection.adapter_name == 'SQLite'
end
+ def using_mysql?
+ ::ActiveRecord::Base.connection && ::ActiveRecord::Base.connection.adapter_name == 'Mysql2'
+ end
+
def sha_prefix(string)
Digest::SHA1.hexdigest("#{string}#{rand}")[0..6]
end
Something went wrong with that request. Please try again.