我有一个 Rider 表,其中包含他们的城市。我正在从数据库中提取与当前用户所在城市匹配的条目。
这就是我在 Controller 中写的内容:
@riders = Rider.where("city = ?", current_user.profile.location.split(",")[1] )
但它正在重新调整 null,就好像没有任何内容与“current_user.profile.location.split(",")[1]"匹配
如果“current_user.profile.location.split(”,”)[1]”的值为“纽约”并且如果我替换“current_user.profile.location.split(”,”)[1]”上面的查询中包含“New York”,它会返回与 New York 匹配的用户。
我不明白为什么会发生这种情况。
有人可以帮忙吗?
最佳答案
已解决。 它在 city_name 之前占用空间,因此无法与数据库条目匹配。
这样做了:
current_user.profile.location.split(",")[1].lstrip
关于mysql - 导轨 : Mysql query returning null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16739377/