Example application
All patterns and instructions in this documentation refer to the filterrific demo Rails application below. You can view a live demo, and the source for the demo app.
I have included only the parts of the code required to demonstrate Filterrific. In a production app you would have to add a lot more code to handle permissions, strong params, etc.
The Student
model is the primary model which we will filter. It belongs to
the Country
class as shown below:
Class structure
Student
The Student
class is our primary class. This is where we include Filterrific.
1
2
3
4
5
6
7
8
9
10
11
12
# app/models/student.rb
class Student < ActiveRecord::Base
# db columns:
# integer: id
# string: first_name
# string: last_name
# text: email
# integer: country_id
# datetime: created_at
belongs_to :country
end
Country
The Country
class represents the country a Student
belongs to, e.g.,
“Canada”, “United States”, and “Australia”.
Not all students belong to a country.
1
2
3
4
5
6
7
8
# app/models/country.rb
class Country < ActiveRecord::Base
# db columns:
# integer: id
# string: name
has_many :students
end