Skip to content
On this page

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

Default value

40

Possible values

Use any number to size the image.

height

Default value

40

Possible values

Use any number to size the image.

radius

Default value

0

Possible values

Use any number to set the radius value.

link_to_resource

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 |model|
  "//logo.clearbit.com/#{URI.parse(model.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_resource: true do |model|
  "//logo.clearbit.com/#{URI.parse(model.url).host}?size=180"
rescue
  nil
end