purple-park-97233
09/23/2025, 11:24 AMminiature-optician-85831
09/23/2025, 11:24 AMloud-jewelry-99127
09/24/2025, 12:12 AMpurple-park-97233
09/24/2025, 11:39 AMcontent[:title. and I was told by your AI in the docs that this cannot be done in regular fields and so i'd need a custom field.
I looked into this and thought i could create a custom field that could be used something like this:
field :stuff, as: :dynamic_content_from_template,
template: record.template.structure_fields,
content: record.content.fields
I tried this and my Show Component looks like:
<% field.template.each do |name, settings| %>
<% type = settings["type"] %>
<% case type %>
<% when "SingleText" %>
<%= field_wrapper **field_wrapper_args do %>
<%= field.content[name] %>
<% end %>
<% when "RichText" %>
<%= field_wrapper **field_wrapper_args do %>
<%= field.content[name] %>
<% end %>
<% end %>
<% end %>purple-park-97233
09/24/2025, 11:39 AMpurple-park-97233
09/25/2025, 9:36 AMrecord.template.structure_fields.each do |name, settings|
type = settings["type"]
case type
when "SingleText"
field name, as: :text,
format_using: -> { record.content.fields[name] },
for_attribute: :content
when "RichText"
field name, as: :textarea,
format_using: -> { record.content.fields[name] },
for_attribute: :content
when "Image"
field name, as: :file
end
end
end
end
This does make the text and textarea fields actually display on the Edit view (they error when trying to save a change -
> Content(#2214160) expected, got "How things work 2" which is an instance of String(#4440))
Any ideas how I should get this saved back correctly?
The Template I have to work with looks like:
--- !ruby/hash:TemplateStructureHash
title: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
type: SingleText
options: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
validators: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
presence: true
searchable: true
introduction: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
type: RichText
content: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
type: RichText
options: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
validators: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
presence: true
searchable: true
image: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
type: Image
options: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
styles: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
thumbnail: 232
large: x600>loud-jewelry-99127
10/01/2025, 9:32 AMpurple-park-97233
10/01/2025, 12:14 PMloud-jewelry-99127
10/01/2025, 12:22 PMupdate_using if you need to preprocess the data before it hits the DB.