### View Code for Multiple Form Inputs (ERB) Source: http://filterrific.clearcove.ca/pages/active_record_scope_patterns.html Example of how to structure a form using `fields_for` to combine multiple input values for a single scope, such as filtering by distance and city. ```erb <%# app/views/students/index.html.erb Add a `fields_for` helper to your filterrific form: %> <%= form_for @filterrific do |f| %> ...
Distance <%= f.fields_for :with_distance do |with_distance_fields| %><%= with_distance_fields.text_field :max_distance %><% %><%= with_distance_fields.text_field :city %><% end %>
... ``` -------------------------------- ### Add Filterrific Gem to Gemfile Source: http://filterrific.clearcove.ca/ To install Filterrific, add the gem to your application's Gemfile. ```ruby # Gemfile gem 'filterrific' ``` -------------------------------- ### Initialize Filterrific in Controller Source: http://filterrific.clearcove.ca/pages/action_controller_api.html Use `initialize_filterrific` in your controller's index action to set up filterrific. It accepts the model class, params, and various options for customization, including select options, persistence ID, default parameters, available filters, and sanitization. Ensure `||= return` is used for proper redirect on reset. ```ruby class StudentsController < ApplicationController def index # Initialize filterrific with the following params: # * `Student` is the ActiveRecord based model class. # * `params[:filterrific]` are any params submitted via web request. # If they are blank, filterrific will try params persisted in the session # next. If those are blank, too, filterrific will use the model's default # filter settings. # * Options: # * select_options: You can store any options for `