active_element

0.0.13
Light Mode Dark Mode

Types

The following JSON primitives are supported in schema definitions. Note that null cannot be specified as a field type, but it is the default value for most types.

Type Description Ruby Mapping
object A key-value data construct. Hash ({})
array An ordered sequence of objects of any type Array ([])
string A sequence of Unicode characters String ("")
boolean A true or false value TrueClass or FalseClass (true, false)
float A floating-point number Float (0.1)
null An empty value NilClass (nil)

And the following extensions are provided:

Type Description Ruby Mapping
date An iso8601 date stored as YYYY-MM-DD. Date
datetime An iso8601-1:2019 combined date and time stored as YYYY-MM-DDThh:mm:ss DateTime
time An iso8601-1:2019 time stored as hh:mm String (*)
decimal An infinite-precision decimal object stored as a string, e.g. "3.141592653589793" BigDecimal
integer A whole number, stored as a JSON float. Integer

Defining types in your schema allows you to work directly with Ruby objects when the form is submitted to a controller. The params arrive pre-parsed in formats that match the automatic serialization that ActiveRecord performs. e.g. converting a DateTime object to JSON in Rails outputs the following:

irb(main):001:0> puts({ time: Time.now.utc }.to_json)

{"time":"2023-06-12T20:13:11.308Z"}

Time of Day

Note that Ruby has no native way to store a time of day without a date, so time fields are coerced to String (hh:mm) when processed into controller params.

You may find the Tod gem useful when working with these values.


Documentation generated by rspec-documentation