2

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

比如说,我有一个关于书籍的网站。我在 有一个页面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 中实现这样的目标?

4

1 回答 1

2

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

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

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

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

于 2015-06-24T07:14:36.360 回答