为什么这个查询在 Heroku 上不起作用?
尝试使用 RoR 和 Heroku 实现简单的搜索。这在本地主机上运行良好,但一旦我推送到 Heroku,搜索就不会返回任何结果。我在本地使用 SQlite,Heroku 使用 Postgres,对吗?我认为这就是问题所在,但经过大量研究后我似乎找不到解决方案。知道会发生什么吗?一如既往地感谢帮助。
def self.search(search)
if search
where("title LIKE ? OR description LIKE ?", "%#{search}%", "%#{search}%")
else
find(:all)
end
end
Trying to implement a simple search with RoR and Heroku. This works fine on localhost but as soon as I push to Heroku, the search returns no results. I'm using SQlite locally and Heroku uses Postgres, correct? I think this is the problem but after quite a bit of research I can't seem to find the solution. Any idea what might be going on? Help appreciated as always.
def self.search(search)
if search
where("title LIKE ? OR description LIKE ?", "%#{search}%", "%#{search}%")
else
find(:all)
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是因为 SQLite 的 LIKE (部分)不区分大小写,但 PostgreSQL 的 LIKE 区分大小写。试试这个:
PostgreSQL 也有 ILIKE 作为 LIKE 的不区分大小写的版本,但 SQLite(或标准 SQL)没有,所以你不应该使用 ILIKE,除非你专门针对 PostgreSQL。
如果您要发布到 Heroku,请将您的开发环境切换到 PostgreSQL,这样您就会避免一些悲伤和困惑。
另一种可能性是您的 Heroku 数据库中没有任何数据(或任何匹配的数据)。
Probably because SQLite's LIKE is (partially) case insensitive but PostgreSQL's LIKE is case sensitive. Try this:
PostgreSQL also has ILIKE as a case insensitive version of LIKE but SQLite (nor standard SQL) doesn't so you shouldn't use ILIKE unless you are specifically targeting PostgreSQL.
And switch your development environment to PostgreSQL if you're publishing to Heroku, you will save yourself a fair bit of grief and confusion.
Another possibility is that you don't have any data (or any matching data) in your Heroku database.