Search code examples
hanami

How to get flash messages to work in Hanami


I'm trying to figure out how to get flash messages to work in Hanami. The only reference to flash messages that I've found in the official docs are about testing, not actually implementing. If I overlooked something, please point me in the right direction.

I also found the Hanami::Action::Flash class in the source, but haven't been able to discern from that what I'm doing wrong.

So, I forked the official bookshelf demo app and added what I think is a super rudimentary demonstration of the flash message not working as I think it should, based on what I've read, immediately after creating a book. I feel like the message added in the create action should be visible in here somewhere, but all the index page shows (immediately after the redirect), is...

<div id='flash'>#<Hanami::Action::Flash:0x7f442c865408 {}></div>
<div id='message'></div>

What am I doing wrong? Thanks!


Solution

  • do you have sessions enabled? flash is exposed by default as you're using Hanami 1.1.

    Then set it in the action flash[:some_notice] = "Test" and use it in a template.

    regards, Sebastjan