从 rails 3 中的视图获取模板名称 [英] Get template name from a view in rails 3
本文介绍了从 rails 3 中的视图获取模板名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 rails 2 中很容易.视图中有可用的模板变量.现在我找不到获取它的方法.
It was easy in rails 2. There was the template variable available from the view. Now I cannot find the way to get it.
渲染dashboard.html.erb:
Rendering dashboard.html.erb with:
<%= 模板名称 %>
<%= template_name %>
应该产生:仪表板.html.rb
Should produce: dashboard.html.rb
推荐答案
您可以显示当前控制器和操作的可能模板:
You can show the possible templates for the current controller and action:
<%= lookup_context.find_all(params[:action], params[:controller]).inspect %>
这仅适用于您不手动指定模板的情况.
This only applies if you are not manually specifying the template.
这篇关于从 rails 3 中的视图获取模板名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文