Closed
Description
Context
Currently, it’s a common pattern to use format_using
alongside update_using
to render a prettified version of a code field's content while ensuring valid parsing on update. A typical example involves formatting JSON fields like so:
field :body, as: :code,
format_using: -> {
JSON.pretty_generate(JSON.parse(value.to_json))
},
update_using: -> {
JSON.parse(value)
}
This approach, while effective, introduces redundancy and boilerplate code. To streamline this, we propose adding a first-party pretty_generated
option, allowing developers to enable this behavior with a simple flag:
field :body, as: :code, pretty_generated: true
Metadata
Metadata
Assignees
Type
Projects
Status
Done