【发布时间】:2010-10-25 12:14:08
【问题描述】:
对于一个插件,我想在 Rails 中加入以下功能:
当(部分)模板不存在时(无论格式如何),我想呈现默认模板。
假设如果 users/index.html.erb 不存在(或其他格式),我将操作称为“users/index”,则应该呈现“default/index.html.erb”。
同样,如果我调用操作“locations/edit”并且“locations/edit.html.erb”不存在,则应该呈现“default/edit.html.erb”
对于局部,如果我调用一个动作'locations/index'并且模板'locations/index.html.erb'调用不存在的局部'locations/_location',它应该呈现'default/_object'
解决方案是 seek 让我可以访问模板变量(例如@users、@locations)和有关请求路径的信息(例如用户/索引、位置/编辑)。它也应该适用于部分。
我想到了一些选项,我将在下面发布。没有一个是完全令人满意的。
【问题讨论】:
标签: ruby-on-rails render actionview