Skip to content
How-to guides and worked examplesSee the guides →

Code API ​

Per-option reference for the Code field. For worked examples, see the Code guide.

Options are passed to the field declaration in an Avo resource:

ruby
# app/avo/resources/user.rb
field :custom_css, as: :code, language: "css"

For options common to all fields, see shared field options.

Syntax and colors ​

language

The CodeMirror syntax-highlighting mode.

ruby
field :custom_css, as: :code, language: "css"
  • Type: String or Symbol (converted to a string).
  • Default: "javascript".
  • Values: Bundled modes are listed below.
  • Validation: Avo does not validate mode names. Blank values use the default.
ValueBehavior
cssCSS highlighting
dockerfileDockerfile highlighting
htmlmixedHTML with embedded CSS and JavaScript
javascriptJavaScript highlighting
markdownMarkdown highlighting
nginxNginx configuration highlighting
phpPHP highlighting
rubyRuby highlighting
sassSass highlighting
shellShell script highlighting
sqlSQL highlighting
vueVue single-file component highlighting
xmlXML highlighting
yamlYAML highlighting

theme

The CodeMirror theme used in light mode. Dark mode always uses monokai, including when the user switches modes while the editor is open.

ruby
field :custom_css, as: :code, theme: "monokai"
  • Type: String or Symbol (converted to a string).
  • Default: "default".
  • Validation: Avo does not validate theme names. Blank values use the default.
ValueBehavior
defaultCodeMirror's default light theme
monokaiBundled dark theme, also usable in light mode

Additional themes

Only default and monokai have styles bundled with Avo. Other names are forwarded to CodeMirror but need separately loaded theme styles.

Display ​

always_show

Controls whether the Show view displays the full content or a collapsed, faded preview with More content and Less content controls.

ruby
field :custom_css, as: :code, always_show: true
  • Type: Boolean.
  • Default: false.
ValueBehavior
falseCollapsible preview on Show
trueFull content on Show

height

The editor height on Show. Edit and New use the resizable viewport instead and ignore this option.

ruby
field :custom_css, as: :code, height: "250px"
  • Type: String (nonblank inputs are converted to strings).
  • Default: "auto".
  • Values: "auto" or a CSS height such as "250px".
  • Validation: Avo does not validate CSS values. Blank values use the default; numeric inputs do not acquire a px unit.

line_wrapping

Controls line wrapping in the editor.

ruby
field :custom_css, as: :code, line_wrapping: true
  • Type: Boolean.
  • Default: true.
ValueBehavior
trueWraps long lines
falseCurrently falls back to true and also wraps long lines

False does not disable wrapping

The current field initialization treats false as blank and replaces it with the default true.

Indentation ​

tab_size

The width of a tab character in the editor.

ruby
field :custom_css, as: :code, tab_size: 4
  • Type: Integer.
  • Default: 2.
  • Validation: Avo does not enforce a numeric type or range; the value is forwarded to CodeMirror through a data attribute. Blank values use the default.

indent_with_tabs

Controls whether indentation uses tabs rather than spaces.

ruby
field :custom_css, as: :code, indent_with_tabs: true
  • Type: Boolean.
  • Default: false.
ValueBehavior
falseIndents with spaces
trueIndents with tabs

JSON values ​

pretty_generated

Installs default formatting and saving callbacks for JSON columns. Display and form values pass through JSON.pretty_generate; submitted values pass through JSON.parse. Blank values pass through unchanged. Explicit format_using and update_using callbacks override the respective defaults.

ruby
field :metadata, as: :code, language: "javascript", pretty_generated: true
  • Type: Boolean.
  • Default: false (disabled when omitted).
  • Validation: Nonblank invalid JSON raises JSON::ParserError during parsing; this option does not provide an inline JSON validation error.
ValueBehavior
falseDoes not install JSON callbacks
trueInstalls JSON callbacks unless explicitly provided