External image
You may have a field in the database that has the URL to an image, and you want to display that in Avo. That is where the ExternalImage
field comes in to help.
It will take that value, insert it into an image_tag
, and display it on the Index
and Show
views.
ruby
field :logo, as: :external_image
Options
-> width
-> height
-> radius
-> link_to_record
Wraps the content into an anchor that links to the resource.
Use computed values
Another common scenario is to use a value from your database and create a new URL using a computed value.
ruby
field :logo, as: :external_image do
"//logo.clearbit.com/#{URI.parse(record.url).host}?size=180"
rescue
nil
end
Use in the Grid cover
position
Another common place you could use it is in the grid :cover
position.
ruby
cover :logo, as: :external_image, link_to_record: true do
"//logo.clearbit.com/#{URI.parse(record.url).host}?size=180"
rescue
nil
end