Class: Plutonium::UI::Form::Components::Json
- Inherits:
-
Phlexi::Form::Components::Textarea
- Object
- Phlexi::Form::Components::Textarea
- Plutonium::UI::Form::Components::Json
- Defined in:
- lib/plutonium/ui/form/components/json.rb
Overview
Textarea-based input for ‘json` / `jsonb` columns.
On render, serializes Hash/Array values to pretty JSON so users see valid JSON instead of Ruby ‘Hash#to_s` output (e.g. `:k=>“v”`). Strings are pretty-formatted if parseable, passed through verbatim otherwise — preserves an in-progress edit on form re-render.
On submit, accepts either a JSON string (typed input) or a raw Hash/Array (e.g. a JSON-bodied API request that Rails has already parsed into params). Unparseable strings are passed through so model validation can surface the error, rather than being silently dropped.
Instance Method Summary collapse
Instance Method Details
#view_template ⇒ Object
21 22 23 |
# File 'lib/plutonium/ui/form/components/json.rb', line 21 def view_template textarea(**attributes) { serialized_value } end |