I've been pouring over this issue for weeks avoiding having to post here, but I just can't seem to work this issue out! (PS I'm relatively new to Rails but am soaking up as much as humanly possible). I have three search parameters: a regular search text field, a dropdown to filter by university and another one to filter by program. Trying to filter by any one of those three brings the spinner up, but nothing actually happens. I only have 5 entries as dummy data in my db, so I know it's not an issue with returning too many results or something of that nature. Hopefully it's something simple and I can feel dumb for a few minutes before moving on! Thanks in advance for your help.
Filterrific: 2.1.2
Rails: 4.1.9
Ruby: 2.3.3
User Model
filterrific(
# default_filter_params: { sorted_by: 'created_at_desc' },
available_filters: [
# :sorted_by,
:search_query,
:with_university_id,
:with_program_id
# :admin,
# :student
]
)
has_many :typing_tests
belongs_to :university
has_many :programs, through: university
# default for will_paginate
self.per_page = 10
scope :search_query, lambda { |query|
return nil if query.blank?
# condition query, parse into individual keywords
terms = query.downcase.split(/\s+/)
# replace "*" with "%" for wildcard searches,
# append '%', remove duplicate '%'s
terms = terms.map { |e|
(e.gsub('*', '%') + '%').gsub(/%+/, '%')
}
# configure number of OR conditions for provision
# of interpolation arguments. Adjust this if you
# change the number of OR conditions.
num_or_conditions = 2
where(
terms.map { |term|
"(LOWER(users.first_name) LIKE ? OR LOWER(users.last_name) LIKE ?)"
}.join(' AND '),
*terms.map { |e| [e] * num_or_conds }.flatten
)
}
scope :with_university_id, lambda { |university_ids|
where(university_ids: [*university_ids])
}
scope :with_program_id, lambda { |program_ids|
where(program_ids: [*program_ids])
}
University Model
class University < ActiveRecord::Base
has_many :programs
has_many :users, through: :programs
def self.options_for_select
order('LOWER(name)').map { |e| [e.name, e.id] }
end
end
Program Model
belongs_to :university
has_many :users
def self.options_for_select
order('LOWER(name)').map { |e| [e.name, e.id] }
end
end
Users Controller
class UsersController < ApplicationController
before_action :set_user, only: [:edit, :update, :destroy]
before_filter :authenticate_user!
before_action :check_if_admin
# GET /users
# GET /users.json
def index
@filterrific = initialize_filterrific(
User,
params[:filterrific],
:select_options => {
with_university_id: University.options_for_select,
with_program_id: Program.options_for_select,
# with_role: @roles.options_for_select
},
) or return
@users = @filterrific.find.page(params[:page])
respond_to do |format|
format.html
format.js
end
rescue ActiveRecord::RecordNotFound => e
# There is an issue with the persisted param_set. Reset it.
puts "Had to reset filterrific params: #{ e.message }"
redirect_to(reset_filterrific_url(format: :html)) and return
end
end
I've been pouring over this issue for weeks avoiding having to post here, but I just can't seem to work this issue out! (PS I'm relatively new to Rails but am soaking up as much as humanly possible). I have three search parameters: a regular search text field, a dropdown to filter by university and another one to filter by program. Trying to filter by any one of those three brings the spinner up, but nothing actually happens. I only have 5 entries as dummy data in my db, so I know it's not an issue with returning too many results or something of that nature. Hopefully it's something simple and I can feel dumb for a few minutes before moving on! Thanks in advance for your help.
Filterrific: 2.1.2 Rails: 4.1.9 Ruby: 2.3.3
User Model
University Model
Program Model
Users Controller
Users Index
List Partial
Finally my stack trace from terminal: