轨道。不比较unicode字符
我有一个像博客一样简单的应用程序,其中帖子可以属于类别。问题是,我的应用是法语,其中一个类别是“l'épidémieDecovid-19”。当我检查该类别是否已经存在时,它总是返回false:
if Category.exists?(title: title)
# -> Always false when the title is 'l'épidémie de COVID-19', even though it does already exist
如果我使用“ covid-ben-ben”或“ emovernement”之类的标题,则代码正常,但是当我具有''特殊'字符(例如é,è等)等
时有办法解决这个问题吗?谢谢
编辑: databse:sqlite3
列类型:T.String“类别”
生成的SQL:
SELECT 1 AS one FROM "posts" WHERE "posts"."category" = ? LIMIT ? [["category", "l'épidémie de COVID-19"], ["LIMIT", 1]]
I have a simple blog-like application where a post can belong to a category. The thing is, my application is in French and one of the categories is "l'épidémie de COVID-19". When I check if the category already exists, it always returns false:
if Category.exists?(title: title)
# -> Always false when the title is 'l'épidémie de COVID-19', even though it does already exist
The code works fine if I use titles like "Covid-19" or "Environnement", but not when I have 'special' characters like é, è, etc.
Is there a way to solve this? Thank you
Edit:
Databse: sqlite3
Column type: t.string "category"
Generated SQL:
SELECT 1 AS one FROM "posts" WHERE "posts"."category" = ? LIMIT ? [["category", "l'épidémie de COVID-19"], ["LIMIT", 1]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试设置
编码:utf8
在config/database.yml
和config.encoding =“ utf-8”
中application.rbTry to set
encoding: utf8
in yourconfig/database.yml
andconfig.encoding = "utf-8"
inconfig/application.rb