TIL: Pass a Hash to Flash
Today I learned:
You are free to pass a HASH to a flash message. Not just a string 😀
# app/controllers/posts_controller.rb
flash[:post_status] = "Success. Post created" # a string
flash[:post_status] = { title: "Success", subtitle: "Post created" } # a hash!
# app/views/shared/_flash.html.erb
<% flash.each do |type, message| %>
<%= type %>
<%= message[:title] %>
<%= message[:subtitle] %>
<% end %>
- More about ActionDispatch::Flash (official docs)
- Dismissable Flash Messages with Hotwire without page refresh
Did you like this article? Did it save you some time?