轨道。不比较unicode字符

发布于 2025-01-27 20:05:47 字数 576 浏览 3 评论 0原文

我有一个像博客一样简单的应用程序,其中帖子可以属于类别。问题是,我的应用是法语,其中一个类别是“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2025-02-03 20:05:47

尝试设置编码:utf8config/database.yml

config.encoding =“ utf-8”中application.rb

Try to set encoding: utf8 in your config/database.yml and

config.encoding = "utf-8" in config/application.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文