Rails set layout from within a before_filter method

前端 未结 3 1149
闹比i
闹比i 2020-12-31 01:34

Is it possible to reset a default layout from within a before_filter method in Rails 3?

I have the following as my contacts_controller.rb:

cla         


        
3条回答
  •  甜味超标
    2020-12-31 01:53

    From Rails guides, 2.2.13.2 Choosing Layouts at Runtime:

    class ProductsController < ApplicationController
      layout :products_layout
    
      private
    
      def products_layout
        @current_user.special? ? "special" : "products"
      end
    end
    

提交回复
热议问题