Rails response_with json问题

时间:2014-01-23 16:28:42

标签: ruby-on-rails json autocomplete

现在我正在努力制作一个铁轨形式。该表单具有允许用户查找或创建场地的文本字段。在后端,我想通过场地名称(我知道该怎么做)找到或创建,但我还想自动填写该表格字段。我收到了遗留代码,但对它不太熟悉。现在,我的控制器响应json,这是我正在使用的动作的内容:

@results = Venue.where("lower(name) like?", params)
respond_with(@results)

然后,当我去运行这个,并试着在文本中进入该领域时,这就是我在终端中得到的内容:

Processing by TagsController#locations as JSON
  Parameters: {"term"=>"td", "size_type"=>"in_one_place", "include_button_venue"=>"true"}
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 1]]
  Venue Load (1.0ms)  SELECT "venues".* FROM "venues" WHERE (lower(name) like'---
- term
- td
','---
- size_type
- in_one_place
','---
- include_button_venue
- ''true''
','---
- action
- locations
','---
- controller
- tags
')
PG::Error: ERROR:  argument of WHERE must be type boolean, not type record
LINE 1: SELECT "venues".* FROM "venues"  WHERE (lower(name) like'---
                                               ^
: SELECT "venues".* FROM "venues"  WHERE (lower(name) like'---
- term
- td
','---
- size_type
- in_one_place
','---
- include_button_venue
- ''true''
','---
- action
- locations
','---
- controller
- tags
')
Completed 500 Internal Server Error in 8ms

ActiveRecord::StatementInvalid - PG::Error: ERROR:  argument of WHERE must be type boolean, not type record
LINE 1: SELECT "venues".* FROM "venues"  WHERE (lower(name) like'---
                                               ^
: SELECT "venues".* FROM "venues"  WHERE (lower(name) like'---
- term
- td
','---
- size_type
- in_one_place
','---
- include_button_venue
- ''true''
','---
- action
- locations
','---
- controller
- tags
'):

这是好事还是坏事。我没有加载场地,但一定是做错了。有任何想法吗?具体来说,我想按地点名称搜索。

1 个答案:

答案 0 :(得分:0)

似乎您将所有参数传递给搜索查询。

如果你想通过'term'参数搜索(在你的情况下是'td')你可以尝试这个

Venue.where("lower(name) like ?", params[:term])