为某些操作设置布局? [英] set a layout for certain actions?
本文介绍了为某些操作设置布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 app/views/layouts 文件夹如下所示:
My app/views/layouts folder looks like this:
application.html.erb
user_sessions.html.erb
errors.html.erb
这些工作正常,我对它们没有任何问题,但 id 现在想为提示添加新布局,但仅限于索引和显示操作.
These work fine and i have no problems with them but id now like to add a new layout for tips, but only on the index and show actions.
tips.index.html.erb"会起作用吗?
Would "tips.index.html.erb" work?
推荐答案
添加一个名为tips.html.erb"的新布局
Add a new layout as you like called 'tips.html.erb'
在提示控制器中添加以下内容:
In the tips controller add the following:
layout "tips", :only => [ :index, :show ]
您可以使用以下方法为特定操作指定布局:
You can specify the layout for a specific action using:
def new
render(:layout => "layouts/application")
end
我从未尝试过在控制器中使用多个布局声明.可能是添加另一个
I have never tried using multiple layout declarations in a controller. It might be that adding another
layout "standard", :only => [ :new, :edit ]
可能有用...
这篇关于为某些操作设置布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文