Skip to content
On this page

Text

The Text field renders a regular <input type="text" /> element.

ruby
field :title, as: :text

Options

as_html

Displays the value as HTML on the Index and Show views. Useful when you need to link to another record.

ruby
field :title, as: :text, as_html: true do |&args|
  '<a href="https://avohq.io">Avo</a>'
end

Default

false

Possible values

true, false

protocol

Render the value with a protocol prefix on the Index and Show views. So, for example, you can make a text field a mailto link very quickly.

ruby
field :email,
  as: :text,
  protocol: :mailto
Watch the demo video

Default

nil

Possible values

mailto, tel, or any other string value you need to pass to it.

Wraps the content into an anchor that links to the resource.

Customization

You may customize the Text field with as many options as you need.

ruby
field :title, # The database field ID
  as: :text, # The field type
  name: 'Post title', # The label you want displayed
  required: true, # Display it as required
  readonly: true, # Display it disabled
  as_html: true # Should the output be parsed as html
  placeholder: 'My shiny new post', # Update the placeholder text
  format_using: -> { value.truncate 3 } # Format the output