Virtus: Coercing boolean attributes
TLDR
Do it like this:
attribute :active, Virtus::Attribute::Boolean
Long story
In Virtus Show archive.org snapshot you define attribute with their type like this:
attribute :name, String
attribute :birthday, Date
When defining a boolean attributes, you will probably write it like this:
attribute :active, Boolean
The problem is, there is not actually a Boolean
class in Ruby (there's only TrueClass
and FalseClass
), so use Virtus::Attribute::Boolean
instead.
The reason while Boolean
sometimes survives compilation is that many libraries define a global Boolean
class for some reason. That class however won't work with virtus.