# 教程：运行 Sinatra 应用程序

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/ruby/llms.txt).

[Sinatra](https://github.com/sinatra/sinatra) 是一个用于创建 Web 应用程序的库。 RubyMine 允许您直接以 [Ruby 脚本](running-ruby-scripts.html) 的形式运行 Sinatra 应用程序，或者如果您使用   rackup   工具，也可以通过专用的 [Rack](rack.html) 运行/调试配置运行。

在本教程中，我们将向您展示如何在 RubyMine 中直接以 Ruby 脚本的形式运行 [示例 Sinatra 应用程序](https://github.com/rubyminedoc/palindrome_app)，如何使用   rackup   工具运行应用程序，以及如何使用 [运行/调试配置](run-debug-configuration.html) 配置其他运行选项。

> **Note:**
> 通过以下链接克隆示例应用程序： [palindrome_app](https://github.com/rubyminedoc/palindrome_app)

## 先决条件

在运行 Sinatra 应用程序之前，请确保满足以下先决条件：

* 'sinatra' 和 'rack' gems [已安装](using-the-bundler.html) 到项目解释器。

* 所需的 Web 服务器 gem（例如 'thin' 或 'puma'）已安装到项目解释器。

## 以 Ruby 脚本的形式运行应用程序

Procedure: 运行应用程序

要以 Ruby 脚本的形式运行 Sinatra 应用程序，请按照以下步骤操作：

1. 按两次 `Ctrl` (Windows), `Ctrl` (macOS), `Ctrl` (IntelliJ IDEA Classic (macOS)), `Ctrl` (macOS System Shortcuts), `Ctrl` (XWin), `Ctrl` (GNOME), `Ctrl` (KDE), `Ctrl` (Emacs), `Ctrl` (Sublime Text), `Ctrl` (Sublime Text (macOS)), `Ctrl` (Visual Studio), `Ctrl` (Visual Studio (macOS)), `Ctrl` (TextMate), `Ctrl` (NetBeans), `Ctrl` (Eclipse), `Ctrl` (Eclipse (macOS)) 以调用 [Run Anything](running-anything.html) 弹出窗口。

2. 在弹出窗口中输入以下命令并按下 `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS))。

```CONSOLE
ruby app.rb

```

如有必要，您可以指定所需的命令行选项和脚本参数。 例如，要使用 Puma 服务器运行应用程序，请使用以下命令：

```CONSOLE
ruby app.rb -s Puma

```

在这种情况下，  `-s Puma`  命令部分将作为   脚本参数   传递给创建的 [Ruby 配置](#configure_sinatra_ruby)。

3. 等待 RubyMine 启动应用程序。   运行   工具窗口显示应用程序的输出。

Procedure: 配置运行选项

当您以 Ruby 脚本的形式运行应用程序后，RubyMine 会自动创建 [Ruby](running-ruby-scripts.html#ruby_run_config) 运行/调试配置。 您可以自定义它以传递其他选项。

1. 从主菜单中选择  `运行 | 编辑配置` 。

2. 在打开的   运行/调试配置   对话框中，选择 Ruby 组中创建的   ruby app.rb   配置，并在   脚本参数   字段中传递所需的 [运行选项](https://github.com/sinatra/sinatra#command-line)。 例如，要为此配置使用 Puma 服务器，请指定以下值：

```CONSOLE
-s Puma

```

3. 点击   确定   以保存配置。

## 使用 'config.ru' 运行应用程序

要运行使用  `config.ru`  文件的 Sinatra 应用程序，请按照以下步骤操作：

Procedure:

1. 打开项目视图 `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Meta+1` (TextMate), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))。

2. 右键单击  `config.ru`  并选择   运行 'config.ru'  。

3. 等待 RubyMine 启动应用程序。   运行   工具窗口显示应用程序的输出。

请参阅 [运行 Rack 应用程序](rack.html) 以了解有关运行 Rack 应用程序的更多信息。

