Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:09:32+00:00 2026-06-05T07:09:32+00:00

I want to show flash messages using sinatra-redirect-with-flash gem. Here’s my ruby code: require

  • 0

I want to show flash messages using sinatra-redirect-with-flash gem.

Here’s my ruby code:

require 'sinatra'
require 'sinatra/base'
require 'sinatra/flash'
require 'sinatra/redirect_with_flash'
require 'data_mapper'
require 'haml'
require 'builder'

# ...

class App < Sinatra::Base
  enable :sessions
  register Sinatra::Flash
  helpers Sinatra::RedirectWithFlash
  use Rack::MethodOverride

  get '/' do
    @notes = Note.all :order => :id.desc
    @title = 'All TODOs'
    if @notes.empty?
      flash.now[:error] = 'No TODOs found. Add your first below.'
    end
    haml :home
  end

  post '/' do
    n = Note.new
    n.content = params[:content]
    n.created_at = Time.now
    n.updated_at = Time.now
    if n.save
      redirect '/', :notice => 'TODO saved successfully.'
    else
      redirect '/', :error => 'Failed to save TODO.'
    end
  end

  # ...

end

And views/layout.haml is:

!!! 5
%html{:lang => "en"}
  %head
    %meta{:charset => "utf8"}
  %body
    %header
      %hgroup
        %h1
          %a{:href => "/"}= SITE_TITLE
        %h2= SITE_DESCRIPTION
    #main 
      =styled_flash
      =yield 

After adding a TODO successfully, I expected to see the flash message 'TODO saved successfully.' on the home page. But no flash messages are shown after redirection when I run my app using shotgun. Flash messages are shown well when I run ruby app.rb or rackup.

How can I solve this problem?

Another problem is also happening when I run the app using shotgun. In get '/' method, if I use flash[:error] instead of flash.now[:error], the flash message doesn’t show up on the page.

I am shadowning this tutorial, but I made some differences:

  • erb -> haml
  • Classic Sinatra app -> Subclassing Sinatra::Base
  • rack-flash -> sinatra-flash

You can browse whole codes here.

Thanks for any answers/comments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:09:33+00:00Added an answer on June 5, 2026 at 7:09 am

    The shotgun gem reloads Sinatra after every request. The README says:

    Each time a request is received, it forks, loads the application in
    the child process, processes the request, and exits the child process. The
    result is clean, application-wide reloading of all source files and templates on
    each request.

    As a result, you will need some sort of mechanism to preserve state between requests that doesn’t rely on data stored in each child process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to play stream audio in webview using flash. I'm going to show
(using flash) I have a Sprite object that I want to show on google
I have two flash banners (.swf) and i want to show them randomly on
I'm using Drupal 7 and Views module in my site. And want show number
I am using a FileUpload in my asp.net application. I want to show only
I want to keep a logfile, and I am using TextWriter/StreamWriter to write messages
I want to show flash google map as given on below link http://online.wsj.com/public/resources/documents/info-FDICBANKS111609_RETRO.html Can
I want to show HTML content inside Flash. Is there some way to do
I want to embed and show a flash file. It works fine with document.write
I'm a newbie in flash. I want to click a circle to show a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.