ActionView :: Template :: Error(PG :: UndefinedFunction:ERROR:operator 不存在:双精度~~未知 2016-04-10T23:45:59.506005 + 00:00 app [web.1]:LINE 1:... = “trackers”。“category_id”WHERE(categories.tag LIKE'1。%'...
这是我在这里尝试运行这行代码时得到的错误
Tracker.group(:category_id).joins(:category).where('categories.tag LIKE ? AND user_id = ?', "#{tag.to_i}.%", current_user.id)
标签的类型为 float ,我将其强制转换为整数,以便检查标签1.1,1.2,1.3等
所以在上面的例子中我输入值为1.0的cast标签为1,所以我可以搜索类似1.1,1.2等的标签
我在heroku上使用postgres会出现此错误。本地我使用sqlite3,它工作正常。
我怎么能克服这个?
答案 0 :(得分:1)
Since you're in rails, sort out the dynamic-ness in rails first then send that to the ORM. The syntax you provided already accepts any parameters (eg: WHERE tag between ? and ?), so before you request the data from the ORM, sort out in rails the high and lows. The query is already setup for something to be dynamic.