Use a layout for a specific action

后端 未结 3 554
遥遥无期
遥遥无期 2020-12-29 19:24

If I would like to use a layout for a certain action (say, the show action) that is different from the layout declared at the top of the controller.rb file, how could I do t

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 19:57

    Following example applies desired layout to specific action, otherwise, it uses default layout (layouts/application.html.erb).

    class ArticlesController < ApplicationController
       layout "article_editor", only: [:new, :edit]
    
       def index
         # default layout
       end
    
       def new
         # article_editor layout
       end
    
       def edit
         # article_editor layout
       end
    end
    

提交回复
热议问题