Environment
- Ruby: 3.4.x
- Phlex: 2.4.1
- Context: Standalone script, no Rails
Steps to reproduce
Create a Gemfile:
source "https://rubygems.org"
gem "phlex"
Run bundle install, then create test.rb:
require "phlex"
class MyComponent < Phlex::HTML
def view_template
input(type: "text", disabled: false)
end
end
puts MyComponent.new.call
Run with ruby test.rb.
Error
test.rb:7:in 'Phlex::SGML::Attributes#generate_attributes':
uninitialized constant Phlex::SGML::Attributes::Date (NameError)
when Date
^^^^
Did you mean? Data
Cause
lib/phlex/sgml/attributes.rb references Date and Time in a case/when
value serialiser (lines 31–34) with no require "date" anywhere in the file:
when Date
v.iso8601
when Time
v.respond_to?(:iso8601) ? v.iso8601 : v.strftime("%Y-%m-%dT%H:%M:%S%:z")
Date lives in Ruby's standard library, not core, and must be explicitly
required. It is not auto-loaded in Ruby 3.4 standalone contexts. Rails/ActiveSupport
loads Date very early as a side effect, which is why this error does not
surface in a Rails app — it only appears when using Phlex without Rails.
Time does not cause the same error because Ruby's core library loads it
automatically.
Suggested fix
Add require "date" at the top of lib/phlex/sgml/attributes.rb:
# frozen_string_literal: true
require "date"
module Phlex::SGML::Attributes
# ...
end
Workaround
Add require "date" to your own files alongside require "phlex":
require "phlex"
require "date"
Environment
Steps to reproduce
Create a
Gemfile:Run
bundle install, then createtest.rb:Run with
ruby test.rb.Error
Cause
lib/phlex/sgml/attributes.rbreferencesDateandTimein acase/whenvalue serialiser (lines 31–34) with no
require "date"anywhere in the file:Datelives in Ruby's standard library, not core, and must be explicitlyrequired. It is not auto-loaded in Ruby 3.4 standalone contexts. Rails/ActiveSupport
loads
Datevery early as a side effect, which is why this error does notsurface in a Rails app — it only appears when using Phlex without Rails.
Timedoes not cause the same error because Ruby's core library loads itautomatically.
Suggested fix
Add
require "date"at the top oflib/phlex/sgml/attributes.rb:Workaround
Add
require "date"to your own files alongsiderequire "phlex":