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
'<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
Watch the demo video field :email,
as: :text,
protocol: :mailto
Default
nil
Possible values
mailto
, tel
, or any other string value you need to pass to it.
-> link_to_record
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