I’m currently building a Ruby app using Rack and Sinatra but I’m failing in using routes, implemented in other than the main app file. My first try was like this:
In the main file:
require 'sinatra'
require 'lib/web'
module NoCI
class Main < Sinatra::Base
include NoCI::Web
load 'lib/web.rb'
end
end
and in lib/web.rb:
require ‘sinatra’
module NoCI
module Web
get '/' do
"Hello World"
end
end
end
But it did not work. Then I read about putting the routes into a sub class of my main class. No success either. Any hints, what I’m missing?
Update: I tried with ‘require’, ‘include’ and ‘load’, mixing all possible combinations, nothing worked for me.
You can use
includedhook to implement what you want.lib/web.rb
The code inside
includedwill execute when you include this module, with theNoCI::Baseasbase.