Skip to content


Sinatra::Namespace doesn't seem to work #47

evanleck opened this Issue · 6 comments

4 participants


First off, I'm sorry I can't give you more context or (even better) provide a pull request. I haven't had any luck getting any more detail or information about what's going on and understanding the source for the namespace module is a little beyond me (I've tried :/).

That said, I can't seem to get namespace to work at all outside of a contrived, single Ruby file. I have a main controller file that does a require of another file with this:

# Gemfile
gem 'sinatra'
gem 'sinatra-flash', require: 'sinatra/flash'
gem 'sinatra-contrib', require: 'sinatra/contrib'

# controller.rb
Dir.glob('./**/*.rb') do |file|
  require file.gsub(/\.rb/, '')

get '/' do
  erb 'pages/home'

# sessions.rb
namespace '/login' do
  get do
    "oh hey"

When I go to '/login' I get a "Sinatra doesn't know that ditty" 404. I'm on Sinatra 1.3.2, Sinatra-contrib 1.3.1 on Ruby 1.9.3-p125.


If anyone else is having this issue I've sorta janky-fixed this like so:

'/login'.tap do |path|
  get path do

  post path do
    "oooh nice post"

It works and cleans things up a little bit... sort of... I guess :/


@l3ck the only way I could get namespace to work in a modular app with your structure is if my sessions.rb is written this way:

class App < Sinatra::Base
  register Sinatra::Namespace

  namespace '/login' do
    get do
      "oh hey"

I'm registering the Sinatra::Namespace extension again in an individual controller file.


did u add rake to ur gemfile?

if so, sinatra-contrib namespace will conflict with rake's dsl namespace in the classic mode sinatra app.

rake's namespace is defined here:

to fix this problem:

  • remove rake from ur gemfile


  • mod ur sinatra classic mode app to modular mode.

You're a friggin' genius @SaitoWu ! That did it (I'm on a classic style app)!


@l3ck I think you could probably close this, doesn't seem like it's a Sinatra::Namespace bug per se.
This is nice info though, I was checking Issues because I just started using this extension.


Yeah good point, closing it.

@evanleck evanleck closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.