Closed sidhunavroop closed 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| %>
<%= render_filterrific_spinner %>
<% end %>
<%= render( partial: 'parents/main_admin_list') %>
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?
parentcontroller.rb
def main_admin @filterrific = initialize_filterrific( Parent, params[:filterrific] ) or return
@parents = @filterrific.find.page(params[:page])
mainadmin.html.erb
<%= form_for_filterrific @filterrific do |f| %>
<%= render_filterrific_spinner %>
<% end %>
<%= render( partial: 'parents/main_admin_list') %>