Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 另一个控制器中的Searchkick_Ruby On Rails_Searchkick - Fatal编程技术网

Ruby on rails 另一个控制器中的Searchkick

Ruby on rails 另一个控制器中的Searchkick,ruby-on-rails,searchkick,Ruby On Rails,Searchkick,我是RubyonRails的新手,请帮我解决我的问题 我已经使用了gemsearchkick,在控制台中我可以得到结果 这是我的密码 route.rb resources :m_customers resource :patient, except: [:index, :show] do collection do get 'autocomplete' end end root :to => 'home#index' get 'patient/PatientList',

我是RubyonRails的新手,请帮我解决我的问题

我已经使用了gemsearchkick,在控制台中我可以得到结果

这是我的密码

route.rb

resources :m_customers

resource :patient, except: [:index, :show] do
  collection do
    get 'autocomplete'
  end
end
root :to => 'home#index'

get 'patient/PatientList', to:'patient#PatientList'
get 'patient/PatientList/autocomplete', to:'patient#autocomplete'
get 'patient/PatientHistory/:kode/:histid', to:'patient#PatientHistory', as: 'patient/PatientHistory'
get 'patient/PatientSub/:id', to:'patient#PatientSub', as: 'patient/PatientSub'
get 'patient/PatientObj/:objid', to:'patient#PatientObj', as: 'patient/PatientObj'
get 'patient/PatientAsses/:assid', to:'patient#PatientAsses', as: 'patient/PatientAsses'
get 'patient/PatientPlan/:planid', to:'patient#PatientPlan', as: 'patient/PatientPlan'
m_customer.rb=>模型

class MCustomer < ActiveRecord::Base
  self.primary_key = :Cust_ID

  searchkick match: :word_start, searchable: [:Cust_Name, :Cust_ID]
  MCustomer.search "tipping poi"
 end
但当我插入serch输入时,什么也看不出来

PatientList.html.erb

      <div class="cust-search">
        <%= form_tag patient_PatientList_path, method: :get do %>
          <div class="form-group">
            <%= text_field_tag :query, params[:query], class: 'form-control twitter-typeahead' %>
            <%= submit_tag 'Search', class: 'btn btn-default' %>
          </div>
        <% end %>
      </div>

请帮忙。无论如何,谢谢。

如果您想要工作的自动完成(仅相关部分),那么代码应该是这样的

MyCustomer .RB(你应该考虑把它命名为客户)< /P> 我认为这是您犯错误的地方,您应该提供正确的键,以便该方法能够读取您的json,并检索您想要的名称

您应该查看这本精彩的指南,您可以阅读并复制粘贴,并根据您的代码进行修改:


希望它对任何人都有帮助

我想你可以在github页面中找到足够的细节:我已经阅读了链接,我尝试过,但仍然没有显示任何内容。何时调用自动完成?
     //localhost:3000/patient/PatientList/autocomplete?query=s
      <div class="cust-search">
        <%= form_tag patient_PatientList_path, method: :get do %>
          <div class="form-group">
            <%= text_field_tag :query, params[:query], class: 'form-control twitter-typeahead' %>
            <%= submit_tag 'Search', class: 'btn btn-default' %>
          </div>
        <% end %>
      </div>
 var ready;
  ready = function() {
  var engine = new Bloodhound({
  datumTokenizer: function(d) { 
          return Bloodhound.tokenizers.whitespace(d.name); },
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  remote: { url: '../patient/PatientList/autocomplete?query=%QUERY' }
  });

  // initialize the bloodhound suggestion engine

  var promise = engine.initialize();

  promise 
  .done(function() { console.log('success!'); })
  .fail(function() { console.log('err!'); });

  // instantiate the typeahead UI
  $( '.twitter-typeahead').typeahead(null, {
    displayKey: 'Cust_Name',
    source: engine.ttAdapter()
    });
  }

  $(document).ready(ready);
  $(document).on('page:load', ready);
class MCustomer < ActiveRecord::Base
   searchkick autocomplete: ['Cust_Name']
 end
 class PatientController < ApplicationController

   def autocomplete
     render json: MCustomer.search(params[:query], autocomplete:true, limit: 10).map do |customer| { name: customer.Cust_Name }
     end
   end
 end
  var engine = new Bloodhound({
  datumTokenizer: function(d) { 
          return Bloodhound.tokenizers.whitespace(d.name); },
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  remote: { url: '/patient/autocomplete?query=%QUERY' }
  });

  var promise = engine.initialize();

  $( '.twitter-typeahead').typeahead(null, {
    name: "customer",
    displayKey: "name",
    limit: 20,
    source: engine.ttAdapter()
    });
  }