Helpers
A fun helper that makes rendering placeholder avatars easy.
For testing purposes and demos we leverage a homemade helper demo_avatar_url. This can be passed two options id and variant that returns an absolute URL sourcing the website https://randomuser.me.
The demo_avatar_url helper is accessbile automatically assuming the Rails UI gem is installed. No setup required.
demo_avatar_url(id:, variant:)
id
A number between 1-100.
variant
men, women
<%= image_tag demo_avatar_url(id: 46, variant: "men"), alt: "Demo Avatar", class: "size-16 rounded-full object-cover" %>
<%= image_tag demo_avatar_url(id: 46, variant: "women"), alt: "Demo Avatar", class: "size-16 rounded-full object-cover" %>
<%= image_tag demo_avatar_url(id: 8, variant: "women"), alt: "Demo Avatar", class: "size-16 rounded-full object-cover" %>
= image_tag demo_avatar_url(id: 46, variant: "men"), alt: "Demo Avatar", class: "size-16 rounded-full object-cover"
= image_tag demo_avatar_url(id: 46, variant: "women"), alt: "Demo Avatar", class: "size-16 rounded-full object-cover"
= image_tag demo_avatar_url(id: 8, variant: "women"), alt: "Demo Avatar", class: "size-16 rounded-full object-cover"
def demo_avatar_url(options = {})
id = options[:id] || "22"
variant = options[:variant] || "men"
"https://randomuser.me/api/portraits/#{variant}/#{id}.jpg"
end