Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at <a href="https://stackoverflow.com/a/15699791/335847">https://stackoverflow.com/a/15699791/335847</a> which has some ideas about namespacing.</p> <p>Personally, I would use the config.ru with mapped routes. If you're really in that space between "should this be a separate app or is it just helpful to organize it like this" it allows that, and then later you can still farm off one of the apps on its own without changing the code (or only a little). If you're finding that there's a lot of duplicated set up code, I'd do something like this:</p> <pre><code># base_controller.rb require 'sinatra/base' require "haml" # now come some shameless plugs for extensions I maintain :) require "sinatra/partial" require "sinatra/exstatic_assets" module MyAmazingApp class BaseController &lt; Sinatra::Base register Sinatra::Partial register Sinatra::Exstatic end class Blog &lt; BaseController # this gets all the stuff already registered. end class Foo &lt; BaseController # this does too! end end # config.ru # this is just me being lazy # it'd add in the /base_controller route too, so you # may want to change it slightly :) MyAmazingApp.constants.each do |const| map "/#{const.name.downcase}" do run const end end </code></pre> <p>Here's a quote from <a href="http://shop.oreilly.com/product/0636920019664.do" rel="nofollow noreferrer">Sinatra Up and Running</a>:</p> <blockquote> <p>Not only settings, but every aspect of a Sinatra class will be inherited by its subclasses. This includes defined routes, all the error handlers, <strong>extensions</strong>, middleware, and so on.</p> </blockquote> <p>It has some good examples of using this technique (and others). Since I'm in shameless plug mode I recommend it, even though I've nothing to do with it! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload