为什么我的过滤功能在我的开发机器上运行时无法在 Heroku 上运行?
因此,我有一个页面对我网站上的所有会员进行分页,并且我添加了一个字母链接,以便人们可以按会员名查找会员。它在我的开发机器上运行良好,但在 heroku 上不起作用。
我的控制器有:
def artists
@artists = Member.joins(:member_role).where("member_roles.artist" => true).page(params[:page]).per(20)
@names = Member.joins(:member_role).where("member_roles.artist" => true).where("membername LIKE ?", "#{params[:letter]}%").page(params[:page]).per(20)
end
我的视图有:
<% ('A'..'Z').each do |a|%>
<%= link_to a, {:action => :artists, :controller =>:members, :letter => a } %>
<% end%>
<% if params[:letter].nil? %>
<div class="content">
<%= paginate @artists %>
</div>
<ol class="members_list">
<% @artists.each do |member| %>....
所以我检查是否有任何参数传入,如果没有则显示@artists,否则显示@names。它在我的笔记本电脑上运行完美,但在 Heroku 上却不行
So I have this page that paginates all member on my site, and I added an alphabet link to allow people to find members by their membername. It works fine on my dev machine but it just doesnt work on heroku.
My controller has:
def artists
@artists = Member.joins(:member_role).where("member_roles.artist" => true).page(params[:page]).per(20)
@names = Member.joins(:member_role).where("member_roles.artist" => true).where("membername LIKE ?", "#{params[:letter]}%").page(params[:page]).per(20)
end
and my view has:
<% ('A'..'Z').each do |a|%>
<%= link_to a, {:action => :artists, :controller =>:members, :letter => a } %>
<% end%>
<% if params[:letter].nil? %>
<div class="content">
<%= paginate @artists %>
</div>
<ol class="members_list">
<% @artists.each do |member| %>....
So Im checking to see if there were any parameters passed in and if there are not then @artists is shown otherwise @names is. And it works perfect on my laptop but not in heroku
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜这取决于大小写敏感。
您所说的大多数 MySQL 版本都没有区分大小写的 LIKE。
默认情况下,Postgres 对于 LIKE 区分大小写。要解决此问题,请使用ILIKE:(
请注意 a 周围的通配符“%”)
您确实应该尝试使您的开发环境尽可能接近生产环境,以减轻此类错误。使用 Postgres。
I'm guessing this is down to case-sensitivity.
Most builds of MySQL, which you say you are using, do not have a case-sensitive LIKE.
Postgres, by default, is case sensitive for LIKE. To get around this use ILIKE:
(Note the wildcard '%' around the a)
You really should try to keep your dev env as close to production as possible in order to mitigate this sort of bug. Use Postgres.
当你说它不起作用时 - 有任何错误吗?
您可以尝试heroku log(s?) 看看是否有任何错误。
你在开发中使用什么数据库?你用的是postgres吗?
Heroku 使用 postgres,它有一些特定的怪癖 - 因此,如果您在开发中使用 sqlite 或 mysql,那么您可能会在 Heroku 上得到不同的行为。
和/或在本地使用 postgres。
HTH,Chris
PS Heroku 关于迁移到 postgres 的提示
When you say it doesnt work - are there any errors?
You could try heroku log(s?) to see if there are any errors.
What database are you using in dev? Are you using postgres?
Heroku uses postgres which has some specific quirks - so if you are working with sqlite or mysql in dev, then its possible you might get different behaviour on Heroku.
And/or use postgres locally.
HTH, Chris
PS Heroku tips for migrating to postgres