你能用`phx.gen.html`来生成嵌套资源吗?

时间:2017-12-18 19:48:16

标签: elixir phoenix-framework

如果我的Phoenix / Elixir应用程序中已有资源'Vendors',并且我想在其下添加资源'Devices'作为嵌套资源,我如何使用mix phx.gen.html生成资源?我遇到的问题与路径函数的帮助器有关。即,设备控制器具有device_path功能,当我想要的是vendor_device_path

如果顶级生成器不起作用,我可以使用什么方法来获得此功能?如果手工编码是答案,那很好。

更新以澄清,这是我的电话。 mix phx.gen.html Catalog Device devices name:string vendor_id:references:vendors,其中Catalog是我正在使用的上下文。

第二次更新这是我想支持的router.ex中的结构。

resources "/vendors", VendorController do
  resources "/devices", DeviceController
end

我怀疑发电机不支持开箱即用,对吗?

1 个答案:

答案 0 :(得分:1)

听起来你可能想要利用凤凰称之为Contexts的东西。您的示例可能会转换为:

mix phx.gen.html Vendors Devices devices field1:string --web Vendor

当我在本地运行时,vendor_device_path可用,lib的目录结构如下所示:

lib ├── my_project │   ├── application.ex │   ├── repo.ex │   └── vendors │   ├── devices.ex │   └── vendors.ex ├── my_project.ex ├── my_project_web │   ├── channels │   │   └── user_socket.ex │   ├── controllers │   │   ├── page_controller.ex │   │   └── vendor │   │   └── devices_controller.ex │   ├── endpoint.ex │   ├── gettext.ex │   ├── router.ex │   ├── templates │   │   ├── layout │   │   │   └── app.html.eex │   │   ├── page │   │   │   └── index.html.eex │   │   └── vendor │   │   └── devices │   │   ├── edit.html.eex │   │   ├── form.html.eex │   │   ├── index.html.eex │   │   ├── new.html.eex │   │   └── show.html.eex │   └── views │   ├── error_helpers.ex │   ├── error_view.ex │   ├── layout_view.ex │   ├── page_view.ex │   └── vendor │   └── devices_view.ex └── my_project_web.ex

相关问题