如何使 sinatra 应用程序在 rails 4 中运行? [英] how to make a sinatra app run in rails 4?

查看:33
本文介绍了如何使 sinatra 应用程序在 rails 4 中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Sinatra 应用程序,我想开始在 Rails 中构建新功能,同时仍然支持现有的 Sinatra 功能.我尝试了以下策略:

I have a Sinatra app and I'd like to start building new functionality in Rails while still supporting the existing Sinatra functionality. I've tried the following strategies:

  1. sinatra 的rackup 将一些请求路由到rails,将一些请求路由到sinatra
  2. sinatra 的机架包括导轨
  3. rails 的机架包括 sinatra.

我的许多搜索结果是 rails 3,而不是 4.此外,Rails 是否生成数据库,而不是使用 Sinatra 使用的数据库(在这种情况下,是访问 Sqlite3 的 Sequel gem.) 一般来说,我得到的错误是关于宝石和路径的.(虽然我确实重新捆绑并尝试了不同版本的路径.)

Many of my searches resulted in rails 3, not 4. Additionally, does Rails have to generate the db versus using one that Sinatra was using (in this case, the Sequel gem to access Sqlite3.) In general the errors I was getting were about gems and paths. (Although I did rebundle and try different versions of paths.)

关于在仍支持现有 Sinatra 应用程序的同时使用 Rails 4 的最佳方式有什么建议吗?

Any suggestions on the best way to use Rails 4 while still supporting an existing Sinatra app?

推荐答案

我认为 Rails/Rack 集成代码在 Rails 3 和 4 之间没有太大变化,所以你应该没问题.Rails on Rack Guide 更详细地解释了您可以制作 config.ru 文件用于 Rails 应用程序,如下所示:

I don't think the Rails/Rack integration code has changed very much between Rails 3 and 4, so you should be fine. The Rails on Rack Guide explains in more detail that you can make a config.ru file for a Rails application that looks like:

require ::File.expand_path('../config/environment',  __FILE__)

use Rack::Debugger
use Rack::ContentLength
run Rails.application

然后运行 ​​rackup config.ru 将启动一个运行 Rails 应用程序的机架服务器.

and then running rackup config.ru will start a rack server running your rails app.

这个问题的答案指出如果你从 Rack 运行 Rails 和 Sinatra,而不是在 Rails 的 routes.rb 文件中安装你的 Sinatra 应用程序,对你的 Sinatra 应用程序的请求根本不会通过 Rails.答案还表明,在您的 config.ru 中,您应该能够这样做以支持您的 Sinatra 和 Rails 应用程序:

The answers to this question point out that if you run Rails and Sinatra from Rack, rather than mounting your Sinatra app in Rails' routes.rb file, requests to your Sinatra app won't go through Rails at all. The answers also show that in your config.ru you should be able to do this to support both your Sinatra and Rails apps:

map "/" do
  run RailsApp::Application
end

map "/url1" do
  run SinatraApp1
end

当然,您必须修改路由和应用程序名称以匹配您的需求和应用程序.

You'll have to modify the routes and application names to match your needs and your applications, of course.

我建议您先通过一个 config.ru 运行您的应用程序,然后再询问有关您的数据库的另一个问题,更详细地解释您希望数据库设置是什么以及您的确切错误消息是什么得到是.

I'd recommend getting your apps running through one config.ru first, and then ask another question about your databases, explaining in more detail what you'd like the database setup to be and what the exact error messages you're getting are.

这篇关于如何使 sinatra 应用程序在 rails 4 中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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