Methods
These are the available methods for use in Ruby Views.
Table of Contents
Get data
Example: Get active customers
customers = table("customers", active:true, fields:"name, email")Method
table(table, criteria, fields:, filter:, rows:)tabletable namecriteriaAdd criteria as needed e.g.: school:”fro”, class:”3a”, year:”2001”- if conflict with built in parameters, wrap them in one pair of curly braces {} as parameter 2
fieldscomma separated string of fields to retrive, e.g. fields:”first_name, last_name”filteroptional filter with solr syntax. same as tag “filter”rowsdefault is 20 rows. Increase to improve sorting, or download more files at once. Set ‘MAX_ROWS’ if needed, but check performance when using large values.- Returns empty array [] if no hits
Lookup data
Lookup data in another table. This is similar to using the tag “lookup” in xml
Example: Lookup address_id to find the city
lookup(main:customers, foreignkey:"address_id", table:"address", primarykey:"id", fields:"city")table customers will be updated with the new data
Method
lookup(main:, foreignkey, primarykey:, fields:, table:)mainexisting variable that you want to extend with more dataforeignkeythe foreign key in the main documentprimarykeythe primary key in the lookup tabletablethe lookup table that has more info
Render table
Render the default @docs variable to screen
<%= render 'table' %>Render another table than @docs
If you want to render another table than @docs, you can send the data to the render ‘table’ method
Or you could update the default @docs variable as needed.
<%= render 'table', docs: movies %>docsoptional data to be renderedtitleoptional table titlefieldsfields to show. By default the @show_fields variable will be used.
Adding parameters to the table URL
Sometimes the next view may need extra data from the previous view. We can add those to the link by sending them into the render table method. Any parameter except of docs will be added to the url.
viview indextitable indexprimarykeycomma separated list of primarykeys
NOTE If you reorder the xml, you must update the view and table index
E.g. here we send info about which view was the previous one, in “from_table”. The name of the variable is your choice.
<%= render 'table', vi:1, ti:2, primarykey:"personid", from_table:"report" %>The next view can check this param
<% if params["from_table"] == "report" %>