Feature(s) impacted
Smart Fields (Virtual Attributes) across all collections.
Observed behavior
All Smart Fields are displayed as available fields in the Forest Admin UI (e.g., in table layouts, record views, and are requested in API calls). However, their values are consistently blank. Debugging shows that the Ruby code blocks defined for these smart fields are not being executed by the forest_liana
agent, even though the field
macros themselves appear to be processed during class definition. Example of a smart field not populating below, but it is pervasive across all collections including in dev when I tried a simple string return smart field that didn’t rely on any Active Record Connections.
class Forest::Device
include ForestLiana::Collection
collection :Device
action "Send Update Notification"
action "Send Message", fields: [{
field: "message",
description: "Message to send to device",
type: "String",
is_required: true
}]
action "Enable Meal Ordering Debug Mode", type: "single"
field :patient_present, type: "Boolean" do
object.room && object.room.patient_present?
end
field :device_model, type: "String" do
object.platform ? JSON.parse(object.platform)["deviceModel"] : nil
end
field :mdm_link, type: "String" do
object.mdm_id ? "https://dwiep.esper.cloud/devices/#{object.mdm_id}/information" : nil
end
field :logs_link, type: "String" do
log_types = {
"StaffDevice" => "staff",
"PatientDevice" => "patient",
"HubDevice" => "hub"
}
query_string = CGI.escape "[#{log_types[object.type]}] [#{object.id}]"
"https://app.mezmo.com/23fddf7c5b/logs/view?q=#{query_string}"
end
end
Expected behavior
Smart Fields should execute their defined Ruby code blocks when data is requested, and their computed values should be populated in the Forest Admin UI and present in the API responses.
Context
- Project name: Dispatch
- Team name: Operations
- Environment name: All Environments
- Database type: PostgreSQL
- Agent technology: ruby
- Agent (forest package) name & version (from your .lock file): forest_liana (9.8.0)
Hello @amcwustl, and welcome to our community
Unfortunately, I haven’t been able to reproduce the issue on my side, the smart field doesn’t appear to have any problem rendering when tested in a similar setup.
Could you try replacing object.platform
with a simple string (for example, "Test"
), just to confirm whether the smart field displays anything at all? That would help us determine if the issue is with the field logic or with the field registration.
Also, just to double-check — have you saved your device.rb
file inside the correct path? It should be located at:
lib/forest_liana/collections/device.rb
Feel free to share your findings, and we can take it from there.
Hi @matthv,
Thanks for the response. I originally had my collections in /lib/forest/collections defining classes as Forest::MyCollectionName. Renaming to /lib/forest_liana/collections does appear to work in dev with a simple test as shown below.
class ForestLiana::Collections::OrganizationConfig
include ForestLiana::Collection
collection :OrganizationConfig
field :my_simple_test, type: 'String' do |config_instance|
"Hello from Test #{Time.now.to_i}"
end
end
I had to rename the class ForestLiana as opposed to Forest like it is shown in the docs because I get Zeitwork namespace errors if my class name doesn’t match the folder path. This appears to work at first glance, but can you confirm that there are not any known potential issues or considerations I should be aware of when deviating from the Forest::CollectionName pattern if the directory structure necessitates it for autoloading?
Thanks for taking the time to dig into this and share your findings.
You’re absolutely right: Forest Admin relies on Rails’ autoloading mechanism (Zeitwerk), which requires both the file path and the class name to be strictly aligned. For example, a class defined as ForestLiana::Collections::OrganizationConfig
must be located at
lib/forest_liana/collections/organization_config.rb
.
Even though many projects still use the Forest::YourCollection
namespace, your observation highlights an important point. When using a different namespace like ForestLiana::Collections
, it’s crucial to ensure that the folder structure reflects it exactly. Otherwise, smart fields and other custom logic might not be loaded properly.
Thanks again for identifying this. Your feedback is spot on and could definitely help others running into similar issues.
Let us know if anything else comes up, happy to assist!