这是我的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]

09-25 17:24