Methods

These are the available methods for use in Ruby Views.

Table of Contents

  1. Get data
  2. Lookup data
  3. Render table

Get data

Example: Get active customers

  customers = table("customers", active:true, fields:"name, email")

Method

  table(table, criteria, fields:, filter:, rows:)
  • table table name
  • criteria Add 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
  • fields comma separated string of fields to retrive, e.g. fields:”first_name, last_name”
  • filter optional filter with solr syntax. same as tag “filter”
  • rows default 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:)
  • main existing variable that you want to extend with more data
  • foreignkey the foreign key in the main document
  • primarykey the primary key in the lookup table
  • table the lookup table that has more info

Render table

Render the default @docs variable to screen

  <%= render 'table' %>

Render another table than @docs

Use view index and table index if you want to render another table than @docs
You can also send data into the docs variable.

  <%= render 'table', vi:1, ti:2, primarykey:"personid" %>
  • vi view index
  • ti table index
  • primarykey comma separated list of primarykeys
  • docs optional parameter with data to be rendered

NOTE If you reorder the xml, you must update the view and table index

Adding extra parameters

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.

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" %>