librelist archives

« back to archive

My config blocks run on each request

My config blocks run on each request

Dave Sag
2011-04-15 @ 01:59

I've been programming with Sinatra for a little while and a friend pointed
me at Nesta.  Nice work, it's neat. Like Sinatra.

I've created my own theme, let's call it Frank and based it on the slate
theme for convenience.

In my theme's app.rb I have added my normal configuration blocks for :test,
:development and :production as per how i'd do it in Sinatra (with my app
subclassing Sinatra::Base).


    configure :development do
        set :environment, :development
        @@log =
        @@log.level = Logger::DEBUG"Frank walks onto the stage to rehearse.")

What I have noticed is that this config block gets called with every
request, not just on startup like it does in a regular Sinatra app.

Could somebody run me through just what is happening under the hood.

On that note, one thing that has confused me.  I have seen mention of an
app.rb file being placed at the project level rather than at the theme
level.  This makes sense I'd have thought, given that the theme is more like
a skin than like an app until itself.

But I tried adding an app there with some core routes and helpers (moved
from themes/Frank/app.rb) but they were invisible.  So I've been wondering
how to achieve this.  Most of the code that I currently have running ok in
my theme app.rb is really application specific, not theme specific.  Ideally
when the functionality is built I can then just version in new improved
themes that update the look, or locale without having to duplicate
web-application logic.  Can anyone offer some tips in this area?

Cheers and thanks in advance