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

The Archive Base Latest Questions

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

If my Sinatra Application structure is like this. Copied from Sinatra Help require ‘sinatra/base’

  • 0

If my Sinatra Application structure is like this. Copied from Sinatra Help


require 'sinatra/base'

class LoginScreen  Sinatra::Base
  enable :sessions

  get('/login') { haml :login }

  post('/login') do
    if params[:name] == 'admin' && params[:password] == 'admin'
      session['user_name'] = params[:name]
    else
      redirect '/login'
    end
  end
end

class MyApp  Sinatra::Base
  # middleware will run before filters
  use LoginScreen

  before do
    unless session['user_name']
      halt "Access denied, please login."
    end
  end

  get('/') { "Hello #{session['user_name']}." }
end

The question would be if the two applications require the same configuration such as, helpers, registers and asset-pack. How do I make it consistent between the two application without duplicating the code. Could I do something like this?


require 'sinatra/base'

class LoginScreen  Sinatra::Base
  include_relative("config_file.rb")
  enable :sessions

  get('/login') { haml :login }

  post('/login') do
    if params[:name] == 'admin' && params[:password] == 'admin'
      session['user_name'] = params[:name]
    else
      redirect '/login'
    end
  end
end

class MyApp  Sinatra::Base
  # middleware will run before filters
  include_relative("config_file.rb")
  use LoginScreen

  before do
    unless session['user_name']
      halt "Access denied, please login."
    end
  end

  get('/') { "Hello #{session['user_name']}." }
end

config_file.rb
helpers Sinatra::Helper1
helpers Sinatra::Helper2
helpers Sinatra::Helper3
register Sinatra1
register Sinatra2
register Sinatra3

  • 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-01T22:56:03+00:00Added an answer on June 1, 2026 at 10:56 pm

    How about using inheritance?

    class MyBase < Sinatra::Base
      configure do
        helpers Sinatra::Helper1
        register Sinatra1
      end
    end
    
    class LoginScreen < MyBase
    end
    
    class MyApp < MyBase
      use LoginScreen
    end
    

    This way configuration gets shared among all applications that descend from MyBase.

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

Sidebar

Related Questions

require 'sinatra/base' class Foo < Sinatra::Base get('/foo') { 'foo' } end class Bar <
I have an application class class MyApplication < Sinatra::Base # ... do something ...
I have a Sinatra application I've created and I'd like to package it as
We are using Datamapper in a Sinatra application and would like to use case
I have test app written on ruby, using Sinatra+Sequel. config.ru: require './main' run Sinatra::Application
I would like to mount a sinatra application in my rails app. But I
If I have a config.ru file like this: def my_method 1+2 end require 'my_sinatra_app'
I'm trying to create a custom Liquid template tag like this: class ScriptLoader <
I have a Sinatra app I plan on hosting on Heroku. This application, in
I have a variable in my Sinatra application: get '/' do @agenda_date = Date.today

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.