Skip to content

Preview flash #572

Answered by oliverguenther
alec-c4 asked this question in Q&A
Dec 22, 2023 · 1 comments · 7 replies
Discussion options

You must be logged in to vote

You did not set up flash as an instance variable.

# frozen_string_literal: true

class Elements::FlashComponent < ViewComponent::Base
  def initialize(flash:)
    @flash = flash
    @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 %>

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@Spone
Comment options

@alec-c4
Comment options

@alec-c4
Comment options

@oliverguenther
Comment options

Answer selected by alec-c4
@alec-c4
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants