是否可以使用acts_as_tree 来实现类似文件系统的路由?
我有一个 Folder
模型,其中 acts_as_tree
。
路由是否有可能代表文件夹结构?
文件夹:
1: Folder A
2: Folder B
3: Folder C
4: Folder D
5: Folder E
路线:
/folders/1
/folders/1/2
/folders/1/3/4
/folders/1/2/new
/folders/...
这可能吗?
I have a Folder
model which acts_as_tree
.
Is it possible that the routes represent the folder structure?
Folders:
1: Folder A
2: Folder B
3: Folder C
4: Folder D
5: Folder E
Routes:
/folders/1
/folders/1/2
/folders/1/3/4
/folders/1/2/new
/folders/...
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
据我所知,没有简单的方法可以做到这一点。
我认为最好的方法是使用一组命名路由。
我还没有测试过这个,所以不能保证,但即使失败它也应该给你一些提示。
您必须自己形成祖先字符串并将其作为选项传递给 my_x_folder_path。但你应该得到你想要的漂亮的网址。您可能最好将其提取到一个帮助程序中,该帮助程序还可以根据祖先的存在动态选择资源路径或命名路由路径。
So far as I can tell, there's no easy way to do this.
I think the best way to do this is with a set of named routes.
I haven't tested this, so there's no guarantees, but it should give you some hints even if it fails.
You'll have to form the ancestor string yourself and pass it as an option to my_x_folder_path. But you should get the pretty urls you want. You might be better of extracting it to a helper that can also dynamically select the resource path or the named route path based on the existence of ancestors.