Examples
These are som frequently used code snippets for the ruby view.
Table of Contents
- Examples
- Display the main table
- Add a new column for full name
- Provide an alternative value
- Use first part of the string
- Convert utc to local time
- Convert utc to formatted local time
- Using only the date part
- Custom method
- Show blank page if no data
Display the main table
- Will write the content of variable
@docs
that come from xml
Add a new column for full name
Make a new column that combines first name and last name
Provide an alternative value
Show the student grade if it exists, or show a dashed line if its missing
Use first part of the string
E.g. remove time from the string 12.02.2024 11:00
Convert utc to local time
Note
The date will be presented a little different. See next example for formatting.
If you want to format the result at the same time
Using only the date part
Sometimes we only want the date and not the time part
Note
If needed, use in_time_zone.to_date
Custom method
Write out numbers e.g. 3 as “3 tre”, D as “Deltatt” Returns original string if not found
Show blank page if no data
When no data, its good to exit early to avoid errors.