Skip to content

Add pretty_generated option for code fields #3727

Closed
@Paul-Bob

Description

@Paul-Bob

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

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions