gpt4 book ai didi

mysql - ruby 类查询错误

转载 作者:数据小太阳 更新时间:2023-10-29 08:31:27 25 4
gpt4 key购买 nike

这是我的类似 mysql 查询的代码:

def search
params.permit!
@query = params[:query]
respond_to do |format|
@outlet = Outlet.select(:name).where("name like ?","%#{@query}%")
format.json { render json: @outlet }
end
end

它从表中呈现我的所有数据。它不响应查询。你有什么想法吗?

我的路线是:

 namespace :api do
resources :outlets, :defaults => { :format => 'json'}
get 'outlets/auto_complete' => 'outlets#auto_complete', :defaults => { :format => 'json'}
post 'outlets/search' => 'outlets#search', :defaults => { :format => 'json' }

end

development.log是

    Started POST "/api/outlets/search" for 127.0.0.1 at 2015-05-30 16:56:22 +0530
Processing by Api::OutletsController#search as JSON
Parameters: {"outlet"=>{"query"=>"life"}}
[1m[35mOutlet Load (0.1ms)[0m SELECT `outlets`.`name` FROM `outlets` WHERE (name like '%%')
Completed 200 OK in 28ms (Views: 22.3ms | ActiveRecord: 1.7ms)

最佳答案

查看日志 文件和以下跟踪:-

Parameters: {"outlet"=>{"query"=>"life"}}

我发现了问题。您需要执行 @query = params[:outlet][:query]

关于mysql - ruby 类查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30545432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com