ruby - Rack Routing - NoMethodError -
i'm trying set basic routing scheme in rack, however.. can't understand why first route ('/') works, , sec ('/help') doesn't. gets returned in case of '/help' nomethoderror. why that, , how can prepare it? give thanks you.
require 'rack' class myapp def self.call(env) new.call(env) end def self.get(path, &block) @@routes ||= {} @@routes[path] = block end def call(env) dup.call!(env) end def call!(env) @req = rack::request.new(env) @res = rack::response.new @res.write route(@req.path) @res.finish end def route(path) if @@routes[path] @@routes[path].call else 'not found' end end def to_do(arg) arg end end myapp.get '/' 'index' end myapp.get '/help' to_do 'help' end run myapp
ruby routing rack
No comments:
Post a Comment