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 7721529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:56:52+00:00 2026-06-01T03:56:52+00:00

This is an example from a book, a bit modified. It seems like sessions

  • 0

This is an example from a book, a bit modified. It seems like sessions don’t work. Every time I get a new session.

#reporter.rb  

     require 'sinatra/base'
    
    class LoginScreen < Sinatra::Base
    
      #configure(:development) { set :session_secret, "something" }
    
      enable :sessions
    
      get('/login') { erb :login }
    
      post('/login') do
        if params[:user][:login] == 'admin' && params[:user][:password] == 'admin'
          session['user_name'] = params[:user][:login]
          redirect '/'
        else
          session[:notice] = "notice!"
          redirect '/login'
        end
      end
    end
    
    class Reporter < Sinatra::Base
      # "прослойка" будет запущена перед фильтрами
      # enable :sessions
      # use Rack::Session::Pool, :expire_after => 2592000
      #configure(:development) { set :session_secret, "something" }
      use LoginScreen
    
      before do
        unless session[:user_name]
          halt "Access denied, please <a href='/login'>login</a>."
        end
      end
    
      get('/') { "Hello #{session['user_name']}." }
    end

config.ru

require './reporter'
run Reporter

login.erb

   <h1>Main User</h1>
    <h1>Welccome to reporter</h1>
    <p>You must log in with your credentials or as "newcomer" </p>
    
    <form   action="/login" method="post" id="user">
        <p>
            <label>login:</label><br />
            <input type="text" name="user[login]" id="login" />
        </p>
    
        <p>
            <label>Password:</label><br />
            <input type="text" name="user[password]" id="password" />
        </p>
    
        <p>
            <input type="submit" value="Log in">
        </p>
    </form>

I’m using

  • ruby 1.9.2
  • sinatra 1.3.2
  • shotgun -s thin -p 4567 – how I start server

I just can’t understand why sessions don’t save data?

  • 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-01T03:56:53+00:00Added an answer on June 1, 2026 at 3:56 am

    Why did you comment

    set :session_secret, "something"
    

    in your examples?
    If you use shotgun for reloading server it can help you.

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

Sidebar

Related Questions

thank you for looking i got this example from my book but i cant
i don't understand this example from the doc : the timeIntervalSinceNow method should show
This example was taken from Stroustup's book, third edition, Section 14.4.2 : void f
I am a bit confused here. This is from a great C book, and
This example is taken from the Linux System Programming book, page 88. Code: http://pastebin.com/mEfmHbPP
I looked at this example from the C# in nutshell book ( http://www.albahari.com/nutshell/ch04.aspx )
All examples are taken from the SICP Book: http://sicpinclojure.com/?q=sicp/1-3-3-procedures-general-methods This was motivated from the
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval
In this example from the App Engine docs , why does the example declare
in this example from opencv, why didn't we create a simple variable img (instead

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.