每个动作的Rails布局? - Rails layouts per action?

问题:

I use a different layout for some actions (mostly for the new action in most of the controllers). 我对某些操作使用不同的布局(主要用于大多数控制器中的新操作)。

I am wondering what the best way to specify the layout would be? 我想知道指定布局的最佳方法是什么? (I am using 3 or more different layouts in the same controller) (我在同一个控制器中使用3个或更多不同的布局)

I don't like using 我不喜欢用

render :layout => 'name' 渲染:layout =>'name'

I liked doing 我喜欢这样做

layout 'name', :only => [:new] layout'name',:only => [:new]

But I can't use that to specify 2 or more different layouts. 但我无法使用它来指定2个或更多不同的布局。

For example: 例如:

When I call layout 2 times in the same controller, with different layout names and different only options, the first one gets ignored - those actions don't display in the layout I specified. 当我在同一个控制器中调用布局2次,使用不同的布局名称和不同的选项时,第一个被忽略 - 这些操作不会显示在我指定的布局中。

Note: I'm using Rails 2. 注意:我正在使用Rails 2。


解决方案:

参考一: https://en.stackoom.com/question/Ch8y
参考二: https://stackoom.com/question/Ch8y
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章