我正在使用rails3-jquery-autocomplete gem在我的rails 3應用程序中自動填充表單中的字段(產品)。用戶可以輸入產品名稱或產品代碼,這兩個產品表格都是字符串列。 一切正常本地,但在Heroku上與標準的500 Heroku的錯誤Ajax請求崩潰:Rails Autocomplete在本地工作,但不在Heroku上,可能是MySQL/Postgre問題
We're sorry, but something went wrong (500)
我覺得這可能是一個postgre/SQL的問題 - 我用mysql本地發展,但是Heroku的運行在postgre SQL數據庫,我在由AJAX自動完成的請求獲得了卡列斯的功能做以下查詢:
def get_autocomplete_items(parameters)
items = Product.select("DISTINCT CONCAT_WS(' ', product_code, title, id) AS full_name, product_code, title, id").where(["CONCAT_WS(' ', product_code, title) LIKE ?", "%#{parameters[:term]}%"])
end
本地,這將返回我的JSON格式的數組,包括所有匹配produc_ids和名稱:
[{"id":"9","label":"xt-pnt-dress_45 - Catherine Malandrino","value":"xt-pnt-dress_45 - Catherine Malandrino"}, ... ]
如果有人有一個想法如何改變它符合heroku或任何其他想法的查詢,我會非常感激。謝謝。
感謝這個詳細的答案 - 它不僅有效,而且還提供了很多有關該主題的背景信息以及最佳實踐的一些提示 - 超級! – tmaximini 2011-12-28 15:03:26
我介紹的一件事情是,如果我製作一個虛擬屬性連接字符串標題和產品代碼,例如'full_name',我想搜索它,我得到一個'ActiveRecord :: StatementInvalid:Mysql :: Error':'where子句'中的未知列'full_name':SELECT'products'。* FROM'products' WHERE(LOWER(full_name )LIKE'%ib%')'錯誤.. – tmaximini 2011-12-29 13:05:33
@frank:另一個選擇是將可搜索的列連接在一起(這裏使用'before_save'回調),然後你可以搜索那個堆。 – 2011-12-29 19:05:08