Allow view/download of filtered records from the documents application.
The primary method of filtering is by adding Search Terms, an optional Sort Term, and a Format Specification to the URL.
For example:
/documents.xml?q[subdivision_name_cont]=or&q[plat_book_cont]=2
Return all records where the subdivision_name contains 'or' and the plat_book contains '2', in xml format.
OR
/documents.json?q[plat_book_or_subdivision_name_cont]=2&q[s]=dated_on
Return all records where the plat_book or subdivision_name contain '2', sorted by dated_on, in json format.
A search term has the following structure:
q[subdivision_name_cont]=or
or:
q[plat_book_or_subdivision_name_cont]=2
A sort term has the following structure:
q[s]=dated_on
?format=xml OR /documents.xml?{query string}Three formats are supported: xls, xml, and json. Xls format triggers download of an Excel-format file with the search results.
Ransack predicates are used to determine what information to match. For instance, an "plat_book_cont" predicate will return all records where an attribute called "plat_book" contains a value using a wildcard query: The SQL equivalent of [plat_book_cont]=2 is
SELECT "documents".* FROM "documents" WHERE("documents"."plat_book" LIKE '%2%')
You can also combine predicates for OR queries:
The SQL equivalent of [vert_or_subdivision_name_cont]=2 is
SELECT "documents".* FROM "documents" WHERE("documents"."plat_book" LIKE '%2%' OR "documents"."subdivision_name" LIKE '%2%')
Below is a table of predicates and their opposites.
Predicate | Meaning | Opposite |
---|---|---|
eq | The eq predicate returns all records where a field is exactly equal to a given value: | not_eq |
matches | The matches predicate returns all records where a field is like a given value. *Note: If you want to do wildcard matching, you may be looking for the cont/not_cont predicates instead. | does_not_match |
lt (less than) | The lt predicate returns all records where a field is less than a given value | gteq (greater than or equal to) |
in | The in predicate returns all records where a field is within a specified list | not_in |
cont | The cont predicate returns all records where a field contains a given value | not_cont |
cont_any (contains any) | The cont_any predicate returns all records where a field contains any of given values | not_cont_any |
start (starts with) | The start predicate returns all records where a field begins with a given value | not_start |
end (ends with) | The end predicate returns all records where a field ends with a given value | not_end |
true | The true predicate returns all records where a field is true. The "1" indicates that to Ransack that you indeed want to check the truthiness of this field. The other truthy values are 'true', 'TRUE', 't' or 'T'. | false |
present | The present predicate returns all records where a field is present (not null and not a blank string). | blank |
null | The null predicate returns all records where a field is null | not_null |