I found nothing about how I can mix-in routes from another module, like this:
module otherRoutes
get "/route1" do
end
end
class Server < Sinatra::Base
include otherRoutes
get "/" do
#do something
end
end
Is that possible?
I found nothing about how I can mix-in routes from another module, like this:
module otherRoutes
get "/route1" do
end
end
class Server < Sinatra::Base
include otherRoutes
get "/" do
#do something
end
end
Is that possible?
I prefer the use of sinatra-contrib gem to extend sinatra for cleaner syntax and shared namespace
sinata-contrib is maintained alongside the sinatra project
Just my two cents:
my_app.rb:
app/routes/health.rb:
app/helpers/application.rb:
config.ru:
You don't do include with Sinatra. You use extensions together with register.
I.e. build your module in a separate file:
And then register:
It's not really clear from the docs that this is the way to go for non-basic Sinatra apps. Hope it helps others.
You could do this:
Unlike Ramaze, Sinatra's routes are not methods, and so cannot use Ruby's method lookup chaining directly. Note that with this you can't later monkey-patch OtherRoutes and have the changes reflected in Server; this is just a one-time convenience for defining the routes.
Well you can also use the map method to map routes to your sinatra apps