jhund / filterrific

Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.
http://filterrific.clearcove.ca
MIT License
910 stars 124 forks source link

undefined method `where' for Object:Class #164

Closed sidhunavroop closed 6 years ago

sidhunavroop commented 6 years ago

I have a parents table. When I write the in the search bar it throws an error undefined method `where' for Object:Class. Kindly help

parent.rb

filterrific( available_filters: [ :search_query ] ) scope :search_query, lambda { |query| return nil if query.blank?

    terms = query.downcase.split(/\s+/)

    terms = terms.map { |e|
        (e.gsub('*', '%') + '%').gsub(/%+/, '%')
    }

    num_or_conds = 2
    parent.where(
        terms.map { |term|
            "(LOWER(parent.parent_1_firstname) LIKE ?) OR (LOWER(parent.email) LIKE ?)"
        }.join(' AND '),
        *terms.map { |e| [e] * num_or_conds }.flatten
    )
}
def self.search(search)
    if search
        where('parent_1_firstname LIKE ?', "%#{search}%")
    else
        all
    end
end

parentcontroller.rb

def main_admin @filterrific = initialize_filterrific( Parent, params[:filterrific] ) or return
@parents = @filterrific.find.page(params[:page])

respond_to do |format|
  format.html
  format.js
end
rescue ActiveRecord::RecordNotFound => e
    puts "Had to reset filterrific params: #{ e.message }"
    redirect_to(reset_filterrific_url(format: :html)) and return
end

mainadmin.html.erb

<%= form_for_filterrific @filterrific do |f| %>

Search <%= f.text_field( :search_query, class: 'filterrific-periodically-observed form-control' ) %>
<%= link_to( 'Reset filters', reset_filterrific_url, ) %>

<%= render_filterrific_spinner %>

<% end %>

<%= render( partial: 'parents/main_admin_list') %>