4
votes

Forgive me if this is a noob question with an obvious answer, but what's the point of using rack-flash in Sinatra?

It feels like rack-flash functionality could easily be written yourself and a gem is a little overkill. Is there something Rack provides that I'm missing?

2

2 Answers

2
votes

The README addresses this:

flash[:notice] = "You can stop rolling your own now."

It feels like rack-flash functionality could easily be written yourself and a gem is a little overkill. Is there something Rack provides that I'm missing?

Yes:

  • It's distributed as a gem, so you don't have to copy your flash implementation across projects. This reusability is key.
  • The interface is consistent with Rails, so future maintainers of your code won't have to study your idiosyncratic implementation.
  • It's well tested and developed in a community.
  • You're not wasting your time reinventing a small cog.

Unless your app's core functionality is flashing messages, this little ~100 SLOC gem that provides the above benefits is hardly overkill.

0
votes

I just add a message to my session data and flash it if it's there. That's what rack-flash does too. I looked at it once and the time I need to look up its API is the time I need to write it myself over and over again. Maybe I'm missing something here but iirc one of the flash gems broke over some Sinatra update and that's where the pain starts if you depend on a gem.