简体   繁体   English

Rails App搜索栏可在本地使用,但不能在Heroku上使用

[英]Rails App search bar works locally but not on Heroku

EDIT: Not a duplicate of "Why doesn't this query work on Heroku?" 编辑:不重复的“为什么此查询在Heroku上不起作用?” . Search does not involve strings, only date queries. 搜索不涉及字符串,仅涉及日期查询。

Rails App throws no errors locally when searching but throws an error every time when searching on prod. 搜索时,Rails App在本地不会引发任何错误,但是在产品上进行搜索时,每次都会引发错误。 This used to work fine. 过去工作正常。 I'm developing against SQLite3 and haven't changed anything directly interacting with the search bar recently. 我正在针对SQLite3进行开发,最近还没有更改与搜索栏直接交互的任何内容。 I rolled back to some pretty old branches to make sure; 我回滚到一些相当古老的分支机构以确保; it was still broken. 它仍然被打破。 I've got SQLite3 running on 1.3.9, specified in my gemfile. 我已经在gemfile中指定的1.3.9上运行了SQLite3。

Here is the search def from my model: 这是我的模型的搜索定义:

def self.search(search)
   where("startDay LIKE ?", "%#{search}%")
end

The view: 风景:

<%= form_tag(weeks_path, :method => "get", id: "search-form") do %>
    <h4>Search for weeks by start date </h4>
    <%= text_field_tag :search, params[:search], placeholder: "Search Weeks", value: Date.today.beginning_of_week(:sunday) - 7 %>
    <%= submit_tag "Search", :name => nil %>
<% end %>

Anything else I should include that might help solving the issue? 我应该包括的其他内容可能有助于解决问题?

The main thing is not about searching for strings or dates. 最主要的不是搜索字符串或日期。 The problem is that your local database is different from production one. 问题在于您的本地数据库与生产数据库不同。 PostgreSQL can't apply LIKE operation directly on datetime fields, it should be explicitly converted to a string before using a string operation. PostgreSQL不能直接在datetime字段上应用LIKE操作,应该在使用字符串操作之前将其明确转换为字符串。 Without switching to production type database in your development environment you will continue obtaining similar kind of bugs in future. 在开发环境中无需切换到生产类型数据库,将来您将继续获得类似的错误。

In postgresql this query should be written as follows: 在postgresql中,此查询应编写如下:

 where("startDay::text LIKE ?", "%#{search}%")

For anyone looking at this in the future. 对于任何将来看这个的人。 I switched to postgreSQL, but because my app is 99% complete, I decided that rather than trying to go back through my files and change all of my syntax I would abandon Heroku, continue to use sqlite3 and instead host my own production server. 我改用了postgreSQL,但是由于我的应用程序完成了99%,所以我决定不放弃我的文件并更改所有语法,而是放弃Heroku,继续使用sqlite3,而是托管我自己的生产服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM