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

  • Home
  • SEARCH
  • 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 8906243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:36:12+00:00 2026-06-15T02:36:12+00:00

Hi if I had a ‘main’ sinatra file with the following code, require ‘sinatra’

  • 0

Hi if I had a ‘main’ sinatra file with the following code,

require 'sinatra'
require "sinatra/reloader"

class MyApp < Sinatra::Base
  configure do
    require "./rest/auth.rb"
    register Sinatra::Reloader
    also_reload '/rest/auth'
  end

  get '/' do
    erb :home
  end
end

And I wanted to put my authentication logic inside of /rest/auth.rb, how can I get /rest/auth.rb to reload in development mode? Must I put the configure block and require sinatra/reloader in every one of my controller files? I’d like for my controllers to inherit the settings of my main class. The code inside of auth.rb is as follows:

class MyApp < Sinatra::Base
  set(:auth) do |*roles|  # <- notice the splat here
    condition do
      unless logged_in?
        session[:success_url] = request.path_info
        redirect '/'
      end
    end
  end

  def logged_in?
    current_user
  end

  def current_user
    if session[:user_id]
      u = User.find(:id=>"#{session[:user_id]}")
    else
      false
    end
  end
end

I need to restart the server for my changes to take place but I can throw that reload code in auth.rb’s configure block though I wouldn’t like to. Any ideas?

  • 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-15T02:36:13+00:00Added an answer on June 15, 2026 at 2:36 am

    Try to rewrite like this

    require 'sinatra/base'
    require "sinatra/reloader"
    
    class MyApp < Sinatra::Base
    
      configure :development do
        register Sinatra::Reloader
        also_reload './rest/auth'
      end
    
      require "./rest/auth.rb"
    
    
      get '/' do
        erb :home
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Had to write the following program for an on line pre java class using,
Had a code smell moment and couldn't decided if its OK for a class
Had this working; at one stage. The problem is the following text is now
I had a question in MySQL, did it correctly. But the book code differs
I had a weird issue arise after using CodeMaid to clean up my code.
Had the following as an interview question a while ago and choked so bad
Had a question and if anyone has found similar issues. It seems my file
Had to deploy some PHP code onto a shared server with only PHP5.2.8. All
Had a basic WinForm question: By default a resx file is created for every
Had a 3rd parties working JAR file in my own project, but I ran

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.