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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:59:39+00:00 2026-06-04T06:59:39+00:00

I have web.rb file that works fine. I wanted to move all require files

  • 0

I have web.rb file that works fine. I wanted to move all require files in one requires.rb file and call this file from all my .rb files and use conditions based on a caller file name to require what is needed.

I tested it on ‘require pp’, ‘ruby-growl’ and and it worked fine. But sinatra won’t load if the require sinatra is in another file.

Can I have require sinatra in a different file? Or better in general can I have require in different file?

using

  • ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  • sinatra (1.3.2)
  • gem 1.3.7

  • running the scripts from dos window by ruby script_name.rb

Few first lines from my requires.rb are below. When I run web.rb I can see the text “loading web requires”. Note that I require ‘rubygems’ for all .rb files. If I comment `require ‘sinatra’ I get an error message ‘web.rb:17: uninitialized constant Rack (NameError)’. If the require is not commented ruby finishes without any message on the screen, no error message either.

called_from=caller[0].split(":")[0]
puts "loading web 'requires' for file: #{called_from} ..." if (["web"].any?{|s| called_from[s]})

require "c:\\edutester\\others\\settings.rb"

require 'rubygems'
require 'sinatra'           if (["web"].any?{|s| called_from[s]}) 

UPDATE

I simplified the test case. I have two files. If I use only test.rb and require in the file. Everything works fine. If I use test_require.rb file I can see “loading” text and I’d say that something is loading or something is processin because it takes a second or so to finish the test.rb

test.rb

#require "c:\\edutester\\playground\\test_require.rb"

require 'rubygems' 
require 'sinatra'


get '/' do

    "yes"
end

and test_require.rb

puts "loading..."
require 'rubygems' 
require 'sinatra'

Sinatra won’t load = I don’t get the usual

== Sinatra/1.3.2 has taken the stage on 4567 for development with backup from Thin 
>> Thin web server (v1.2.7 codename No Hup) 
>> Maximum connections set to 1024 
>> Listening on 0.0.0.0:4567, CTRL+C to stop 

and I cannot access the web server from a browser. And there is no message at all. Hm, there is one empty line

  • 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-04T06:59:40+00:00Added an answer on June 4, 2026 at 6:59 am

    When you run a Sinatra program directly with something like ruby my_app.rb, Sinatra can start a web server automatically. Sinatra determines whether to run this built-in server by checking whether the :run setting is true.

    The default for value :run is determined by checking if the :app_file setting is the same as the Ruby file being executed, i.e. $0.

    Sinatra determines the default value for :app_file by using the first file that executes require 'sinatra'. In this case, when you have require 'sinatra' at the top of test.rb then :app_file is $0, so Sinatra starts the built-in server. When you use test_require.rb, $0 is test.rb, but the file to require Sinatra, and therfore :app_file, is test_require.rb, and as they don’t match the built-in server isn’t started.

    To fix this you can explicitly set :app_file in your test.rb (or web.rb or wherever):

    set :app_file, __FILE__
    

    You’ll need to do this after you’ve required Sinatra. You could also directly set :run, although this would be less flexible as it would run the built-in server every time, which you wouldn’t want if you’re using config.ru for example:

    enable :run
    

    Although this should solve your problem, personally I think it would be better to keep the require 'sinatra' together with the Sinatra code.

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

Sidebar

Related Questions

I have a web app that works fine from all browsers (IE9, Firefox, Chrome,
Let's say that I have something like this in my web.xml file. <filter name=foo>
I have a web application that creates directories. The application works fine when creating
Using MVC3.NET I have a file upload method in a controller that works fine
Edit: showed my exact web.config code. I have a MVC3 project that works fine
I have a web application that is deployed with web.config file. Are there any
I have a file that I want to deploy when my web project (an
We have a web application that uses dropbox as file storage. We have currently
I have a website that uses basic ASP.Net forms authentication. In the web.config file
I have some code that loads an image file off the web and puts

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.