【问题标题】:Sinatra doesn't know this dittySinatra 不知道这首小曲
【发布时间】:2020-08-13 08:12:15
【问题描述】:

这是我的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 curl --data "path=URL_HERE" localhost:4567/process 对 /process 进行发布请求,但由于某种原因,我得到了:Sinatra doesn't know this ditty。它告诉我输入一个post /process,我显然有。

有什么想法吗?

【问题讨论】:

标签: ruby sinatra


【解决方案1】:

如果您将以下行添加到类的末尾(:

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

【讨论】:

  • 这是一个重要的时刻——你应该在你的端点声明之后添加它。我花了很多时间才找到它:-(
  • @RuslanValeev 抱歉,我已经添加了另一个示例,以便(我希望)更清楚,并且没有其他人会遭受你的命运。
【解决方案2】:

知道了,问题是我使用 ruby faxattach.rb 而不是 rackup 启动应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 2011-07-19
    • 2021-05-02
    相关资源
    最近更新 更多