2

这是我的faxattach.rb代码:

require 'sinatra'
require 'docsplit'
require './sinatra/faxattach_helpers'

class FaxAttach < Sinatra::Base
  helpers Sinatra::FaxAttachHelpers

      get '/*' do
        "hello world"
        status 405
      end

      put '/*' do
        status 405
      end

      patch '/*' do
        status 405
      end

      delete '/*' do
        status 405
      end

      options '/*' do
        status 405
      end

      link '/*' do
        status 405
      end

      unlink '/*' do
        status 405
      end

      post '/process' do
        path = params[:path]
        begin
          debugger
          file = test_download path
        rescue
          status 404
        end

        debugger
        code = extractCode file
        code
      end

    end

我正在使用 curl 对 /process 进行发布请求curl --data "path=URL_HERE" localhost:4567/process,出于某种原因,我得到了:Sinatra doesn't know this ditty. 它告诉我放入一个post /process我显然拥有的。

有任何想法吗?

4

2 回答 2

4

ruby faxattach.rb如果您将以下行添加到类的末尾,则可以与模块化应用程序一起使用(:

run! if __FILE__ == $0

$0是执行的文件。

__FILE__是当前文件。

例如:

require "sinatra/base"

class App < Sinatra::Base
  get '/' do
    "App is running."
  end
  # add more endpoints...

  # ...then add run! to run if the
  # file has been executed directly.
  # It should be last.
  run! if __FILE__ == $0
end
于 2013-07-02T01:36:37.313 回答
2

明白了,问题是我启动应用程序时使用ruby faxattach.rb的是rackup.

于 2013-07-01T21:56:07.383 回答