Preview flash #572
-
Hey! # frozen_string_literal: true
class Elements::FlashComponent < ViewComponent::Base
def initialize
@flash_class = {
notice: "alert alert-info",
success: "alert alert-success",
error: "alert alert-danger",
alert: "alert alert-warning"
}
end
end <% unless flash.empty? %>
<% flash.each do |key, value| %>
<% next unless value.is_a? String %>
<div class="<%= @flash_class[key.to_sym] %>">
<label><%= sanitize(value) %></label>
</div>
<% end %>
<% end %> and I'd like to add ability to preview flashes. But this code doesn't work class Elements::FlashComponentPreview < ViewComponent::Preview
def default
controller.flash[:notice] = "Flash / Notice"
render Elements::FlashComponent.new
end
end How can I modify it to make it work? |
Beta Was this translation helpful? Give feedback.
Answered by
oliverguenther
Dec 23, 2023
Replies: 1 comment 7 replies
-
Hi @alec-c4 I would advise passing the |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You did not set up
flash
as an instance variable.