Reputation: 92
Here is my code , but 'namespace' is not taking , If I write without namespace it is working , also it will work with 'namespace' if I remove class declaration and execute directly .
require 'sinatra'
require 'sinatra/namespace'
class MyApp < Sinatra::Base
namespace "/v1" do
get "/" do
"Hello World!"
end
end
end
1: from test1.rb:4:in <main>'
test1.rb:5:in
': undefined method `namespace' for MyApp:Class (NoMethodError)
Upvotes: 1
Views: 212
Reputation: 6068
Based on the Sinatra documentation you need to register the extension:
require 'sinatra'
require 'sinatra/namespace'
class MyApp < Sinatra::Base
register Sinatra::Namespace
namespace "/v1" do
get "/" do
"Hello World!"
end
end
end
Upvotes: 3