ProductCardComponent
InfoGenerateCreated ByPackages
This Ruby class defines a component for rendering a product card on a webpage. The ProductCardComponent inherits from ApplicationComponent and is initialized with four attributes: name, image_url, description, and product_link. The `template` method specifies the HTML structure of the card, which includes an image, a title, a description, and a link to view the product. The card is styled using CSS classes.
# frozen_string_literal: true
class ProductCardComponent < ApplicationComponent
def initialize(name:, image_url:, description:, product_link:)
@name = name
@image_url = image_url
@description = description
@product_link = product_link
end
def template
div(class: "card card-compact w-96 bg-base-100 shadow-xl") do
figure { img(src: @image_url, alt: @name) }
div(class: "card-body") do
h2(class: "card-title") { @name }
p { @description }
div(class: "card-actions justify-end") do
a(href: @product_link, class: "btn btn-primary") { "View Product" }
end
end
end
end
end
Try a prompt
Original Prompt:
"a card for my product resource that has a name, an image url, and a description that links to the product page"