如何使用 "template" 控制器制作页面并在 VoltRb 中查看

How to make pages with a "template" controller and view in VoltRb

我在 Volt 中遇到问题,我需要一堆带有 "template" 控制器和视图的页面。让我更详细地解释一下:

例如,我有一个关于书籍的网站。我在 http://localhost:3000/books 有一个页面。它用作其他页面的索引,例如http://localhost:3000/books/fantasy/lord_of_the_rings。我希望所有以书籍为特色的页面都有一个控制器和视图,这样我就不必为要添加的每本书手动添加控制器和视图。相反,我只想将内容添加到以一本书为特色的每一页,以尽可能保持我的工作流程干燥。

因此,app/main/views 下的文件结构如下所示:

views
├── books
│   ├── index.html
│   └── template.html
└── main
    ├── index.html
    └── main.html

app/main/controllers 下的文件结构如下所示:

controllers
├── books_controller.rb
└── main_controller.rb

问题是我不知道如何在 app/main/config/routes.rb 中进行设置,因为我猜那是定义页面 URL 及其控制器、操作等的地方。我该如何实现某些目标在 Volt 中喜欢这样吗?

例如,您可以使用以下路线:

client '/books', controller: 'books', action: 'index'
client '/books/{{ genre }}/{{ title }}', controller: 'books', action: 'template'

这会将两个请求路由到图书控制器。它将通过模板控制器操作和视图中的参数集合使 genretitle 可用。然后,您可以使用此信息从商店(或任何地方)加载正确的图书。

您可以在此处阅读有关路线的更多信息:http://docs.voltframework.com/en/docs/routes_file.html