-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Custom list fields as HTML tags
Alex Wheeler edited this page Aug 16, 2018
·
5 revisions
You can customise list view fields as HTML tags, to replace their defaults with links or images. This saves having to create an entire partial just for a single field.
An example of a link tag showing User.name and linking to the user model within rails admin:
field :name do
pretty_value do
path = bindings[:view].show_path(model_name: 'User', id: bindings[:object].id)
bindings[:view].content_tag(:a, bindings[:object].name, href: path)
end
end
An example of an image field:
field :image do
pretty_value do
bindings[:view].tag(:img, { :src => bindings[:object].image.url })
end
end