轨道 3 和Sinatra 集成问题

发布于 2024-10-02 00:39:17 字数 806 浏览 0 评论 0原文

我正在尝试在 Rails 3 (v3.0.1) 应用程序中设置 sinatra 应用程序,但没有成功。 Sinatra gem (v1.1.0) 使用捆绑安装进行设置。

这就是我所拥有的。

lib 目录中的 customer_app.rb 类 -

class CustomerApp < Sinatra::Base

  get "/test" do
    "Hello World"
  end

end

我的 routes.rb 文件包含 -

CustomerService::Application.routes.draw do

    root :to => CustomerApp

end

我正在尝试的 URL 是 - http://localhost:3000/test

我收到此错误(在浏览器上)- 路由错误。没有路由匹配“/test”

,并且日志中出现此错误 - ActionController::RoutingError(没有路由匹配“/test”):

我缺少什么吗?

我还注意到,即使是简单的机架路线也不起作用 -

root :to => proc { |env| [200, {}, ["Welcome!"]]}

I am trying to set up a sinatra app inside my Rails 3 (v3.0.1) application, but having no success. Sinatra gem (v1.1.0) is setup using bundle install.

Here's what i have.

customer_app.rb class in lib directory -

class CustomerApp < Sinatra::Base

  get "/test" do
    "Hello World"
  end

end

my routes.rb file contains -

CustomerService::Application.routes.draw do

    root :to => CustomerApp

end

The URL i am trying is - http://localhost:3000/test

I get this error (on the browser) - Routing Error. No route matches "/test"

and this error in the log - ActionController::RoutingError (No route matches "/test"):

Is there anything I am missing??

Also I just noticed, even a simple rack route is not working -

root :to => proc { |env| [200, {}, ["Welcome!"]]}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猥琐帝 2024-10-09 00:39:17

默认情况下,root 关键字仅映射路径/

因此,您想说的是,将对 / 的任何请求转发到可以处理 /test 请求的 CustomerApp

您应该更改匹配过滤器。

CustomerService::Application.routes.draw do
  match "/test" :to => CustomerApp
end

The root keyword by default maps only the path /.

So you are trying to say, forward any request for / to CustomerApp which can handle requests for /test.

You should change the match filter.

CustomerService::Application.routes.draw do
  match "/test" :to => CustomerApp
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文