不过滤数据

时间:2019-01-29 07:44:52

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 filterrific

我正在尝试使用Filterrific gem来过滤数据。但是似乎每次我在文本字段中键入内容时,它只会刷新页面并进行过滤。我不希望它刷新页面,它应该是即时的。

型号:

  filterrific(
    default_filter_params: {},
    available_filters: [
      :dictionary_word_filter
    ]
  )

  scope :dictionary_word_filter, lambda { |dictionary_word|
    where("dictionary_word LIKE :search", search: "%#{dictionary_word}%")
  }

控制器:

  def index
    dictionary_types = DimDictionary::DISPLAY_TYPE.map{|key, value| value }
    @dictionary_types_array = DimDictionaryType.where(dictionary_type_name: dictionary_types).pluck(:dictionary_type_name, :dictionary_type_id)
    @filterrific = initialize_filterrific(
      fetch_dictionary_collection,
      params[:filterrific],
      select_options: {},
      persistence_id: 'shared_key',
      default_filter_params: {},
      available_filters: [
          :dictionary_word_filter
        ],
    ) || return

    @dictionaries = @filterrific.find

    respond_to do |format|
      format.html
      format.js
    end
  end

创建了三个文件:

Index.html.haml

= form_for_filterrific @filterrific do |f|
  .ui.form
    .fields
      .field
        Filter Word
        = f.text_field :dictionary_word_filter

  = render_filterrific_spinner

= render(partial: 'test/list', locals: { dictionaries: @dictionaries, dictionary_types_array: @dictionary_types_array })

Index.js.erb

<%  js = escape_javascript(render(partial: 'test/list', locals: { dictionaries: @dictionaries, dictionary_types_array: @dictionary_types_array })) %>

$("#filterrific_results").html("<%= js %>");

_list.html.haml

#filterrific_results
  %strong Test Is Working
  %table.table.dictionary-table
    %thead
      %tr
        %th #
        %th Type
        %th Word
        %th Replacement
    %tbody#dictionary-content-area.clusterize-content
      - counter = 0
      - dictionaries.each do |dictionary|
        - counter = counter + 1
        %tr{ data: {id: dictionary.dictionary_id, index: counter, type: dictionary.dim_dictionary_type.dictionary_type_id}}
          %td
            = counter
          %td#dictionary-type
            = dictionary.dim_dictionary_type.dictionary_type_name
          %td#original-word
            = dictionary.dictionary_word
          %td#replaced-word
            = dictionary.dictionary_replacement

我在这里做错什么了吗?这就是我添加的所有内容。 如何解决此问题..使用Rails 5和ruby 2.5.0

仅添加一下,我没有使用Postgres。使用SQL db

0 个答案:

没有答案