This PR filters People based on this model. Essentially, we whitelist scopes on a model, then apply them sequentially via the filter class method, which is added to a model through the Filterable module (include Filterable). It looks like this: ModelName.filter(filtering_params)
By default, a model's filterable fields and filtering defaults are defined in ModelName.filterable_fields. Conventionally, one calls ModelName.filter(filtering_params) in the controller, where filtering_params is a second controller method that applies the filtering defaults and whitelist.
filtering_params takes an optional hash of filtering defaults, which is useful if defaults must be transformed based on filtering parameters (e.g. in the PeopleController, there should be no default on_date if a for_congress param is passed in). If no hash is passed to filtering_params, non-nil values in ModelName.filterable_fields are regarded as defaults. E.G., in the following, :parameter_with_default defaults to "default_value", while :parameter_without_default will not be applied unless specified:
This PR filters People based on this model. Essentially, we whitelist scopes on a model, then apply them sequentially via the
filter
class method, which is added to a model through theFilterable
module (include Filterable
). It looks like this:ModelName.filter(filtering_params)
By default, a model's filterable fields and filtering defaults are defined in
ModelName.filterable_fields
. Conventionally, one callsModelName.filter(filtering_params)
in the controller, wherefiltering_params
is a second controller method that applies the filtering defaults and whitelist.filtering_params
takes an optional hash of filtering defaults, which is useful if defaults must be transformed based on filtering parameters (e.g. in the PeopleController, there should be no defaulton_date
if afor_congress
param is passed in). If no hash is passed tofiltering_params
, non-nil
values inModelName.filterable_fields
are regarded as defaults. E.G., in the following,:parameter_with_default
defaults to "default_value", while:parameter_without_default
will not be applied unless specified: