問題:
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