即使使用模块化样式实现了默认路由,Sinatra也不知道这个细节 [英] Sinatra doesn't know this ditty even when default route is implemented with modular style

查看:134
本文介绍了即使使用模块化样式实现了默认路由,Sinatra也不知道这个细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行带jruby的MacOS特立独行的软件,并试图编写一个基本的modular sinatra应用程序.这是我的config.ru外观

I'm running MacOS mavericks whith jruby and am trying to write a basic modular sinatra app. Here's what my config.ru looks like

require 'app/app'   
run Sinatra::Application

我用rackup这样调用它,您可以看到404错误-

I invoke it like this with rackup, you can see the 404 errors -

rackup -s puma -p 8080
Puma 2.10.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:8080
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET / HTTP/1.1" 404 437 0.0290
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET / HTTP/1.1" 404 437 0.0980
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET /__sinatra__/404.png HTTP/1.1" 304 - 0.0120
127.0.0.1 - - [17/Jan/2015:18:32:37 -0500] "GET /__sinatra__/404.png HTTP/1.1" 304 - 0.0170

这就是我的source的样子-

➜ less app/app.rb
require 'sinatra/base'

class App < Sinatra::Base

  get '/' do
    "Hello World"
  end
end

如果我将源更改为经典方式

If I change the source to the classic way

➜ cat app/app.rb
require 'sinatra'

#class App < Sinatra::Base

  get '/' do
    "Hello World"
  end
#end

然后像这样调用它,就可以了-

and then invoke it like this, it works just fine -

➜ ruby app/app.rb
Puma 2.10.2 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567
== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from Puma
127.0.0.1 - - [17/Jan/2015:18:36:20 -0500] "GET / HTTP/1.1" 200 11 0.0250

我认为我缺少一些非常明显的配置,但是似乎可以弄清楚那是什么,有人可以让我知道我缺少什么吗?如果需要,我可以分享有关环境的更多详细信息.

I think I'm missing some very obvious config but can seem to figure out what that is, can someone let me know what I am missing? I can share more details about the environment if they are so required.

推荐答案

使用模块化样式时,Sinatra::Application应用仍然存在,但通常没有任何反应.在您的config.ru中,您正在运行此(空)应用程序,而不是您自己的应用程序.只需将run Sinatra::Application更改为

When you use the modular style, the Sinatra::Application app still exists, but usually nothing happens to it. In your config.ru you are running this (empty) app instead of your own. Simply change run Sinatra::Application to

run App

这篇关于即使使用模块化样式实现了默认路由,Sinatra也不知道这个细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆