0

according to http://www.sinatrarb.com/intro.html#Request/Instance%20Scope

You have the request scope binding inside:

  • get, head, post, put, delete, options, patch, link, and unlink blocks
  • before and after filters
  • helper methods
  • templates/views

is there any shortcut to do everything exactly the same despite of methods?

get // do
  # do something
end

post // do
  # do something exactly the same as previous
end

put // do
  # do something exactly the same as previous
end

delete // do
  # do something exactly the same as previous
end

...
4

1 回答 1

3

不确定我是否理解正确。但我认为你会一次捕获多个 http 动词,为此你可以使用多路由

例子

require 'sinatra'
require "sinatra/multi_route"
route :get, :post, '/foo' do
  # "GET" or "POST"
  p request.env["REQUEST_METHOD"]
end

# Or for module-style applications
class MyApp < Sinatra::Base
  register Sinatra::MultiRoute
  route :get, :post, '/foo' do
    # ...
  end
end
于 2013-08-19T13:03:28.953 回答