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

Closed
evanleck opened this Issue Apr 12, 2012 · 6 comments

Comments

Projects
None yet
4 participants
@evanleck

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/, '')
end

get '/' do
  erb 'pages/home'
end

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

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.

@evanleck

This comment has been minimized.

Show comment
Hide comment
@evanleck

evanleck May 3, 2012

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

'/login'.tap do |path|
  get path do
    "haii"
  end

  post path do
    "oooh nice post"
  end
end

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

evanleck commented May 3, 2012

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

'/login'.tap do |path|
  get path do
    "haii"
  end

  post path do
    "oooh nice post"
  end
end

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

@mattreduce

This comment has been minimized.

Show comment
Hide comment
@mattreduce

mattreduce May 8, 2012

Contributor

@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"
    end
  end
end

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

Contributor

mattreduce commented May 8, 2012

@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"
    end
  end
end

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

@SaitoWu

This comment has been minimized.

Show comment
Hide comment
@SaitoWu

SaitoWu May 10, 2012

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: https://github.com/jimweirich/rake/blob/master/lib/rake/dsl_definition.rb#L96

to fix this problem:

  • remove rake from ur gemfile

or

  • mod ur sinatra classic mode app to modular mode.

SaitoWu commented May 10, 2012

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: https://github.com/jimweirich/rake/blob/master/lib/rake/dsl_definition.rb#L96

to fix this problem:

  • remove rake from ur gemfile

or

  • mod ur sinatra classic mode app to modular mode.
@evanleck

This comment has been minimized.

Show comment
Hide comment
@evanleck

evanleck May 10, 2012

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

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

@locks

This comment has been minimized.

Show comment
Hide comment
@locks

locks Sep 9, 2012

@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.

locks commented Sep 9, 2012

@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.

@evanleck

This comment has been minimized.

Show comment
Hide comment
@evanleck

evanleck Sep 10, 2012

Yeah good point, closing it.

Yeah good point, closing it.

@evanleck evanleck closed this Sep 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment