Heroku 搜索损坏 - Rails 3.1
我最近将 Rails 3.1 应用程序推送到了 heroku。在本地,一切正常,但在实时应用程序中,搜索功能被破坏。
模型:
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
结束
视图:
<%= form_tag apps_path, :method => 'get', :id => "search" do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil, :class => "search-button" %>
<% end %>
控制器:
def index
@apps = App.search(params[:search])
@number_of_apps = @apps.count
end
我有一种感觉,这与我的本地设置在 SQLite3 和 Heroku 上运行有关安装程序使用 PostgreSQL。
任何帮助表示赞赏。 :)
I've recently pushed a Rails 3.1 App to heroku. Locally, everything works fine, but in the live app, the search functionality is broken.
Model:
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
View:
<%= form_tag apps_path, :method => 'get', :id => "search" do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil, :class => "search-button" %>
<% end %>
Controller:
def index
@apps = App.search(params[:search])
@number_of_apps = @apps.count
end
I have a feeling that it has to do with the fact that my local setup runs on SQLite3 and the Heroku setup uses PostgreSQL.
Any help is appreciated. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请注意,Postgres 之类的匹配区分大小写。尝试使用
ILIKE
而不是LIKE
Please note that Postgres like matching is case-sensitive. Try using
ILIKE
instead ofLIKE
这里有两个问题:
PostgreSQL
LIKE
关键字与 SQLite 中的LIKE
不同。 SQLite 中的LIKE
与 PostgreSQL 中的ILIKE
相同。使用正确的关键字或小写比较。find(:all)
自 2.3 起已被弃用,应该在 3.1 中删除。请使用#all
方法。更好的是,返回一个范围以利用延迟加载。
There are two issues here:
PostgreSQL
LIKE
keyword is different thanLIKE
in SQLite.LIKE
in SQLite isILIKE
in PostgreSQL. Either use the right keyword or downcase the comparison.find(:all)
has been deprecated since 2.3 and should have been removed in 3.1. Please use the#all
method.Even better, return a scope to take advantage of lazy loading.
您可以使用 Texticle gem。它非常容易安装并且与 Heroku 配合得很好,但您需要使用 PostgreSQL。
You could use the Texticle gem. It's very easy to install and works wonderfully with Heroku, but you need to use PostgreSQL.