How to pass a variable to a layout?

前端 未结 5 2088
时光说笑
时光说笑 2021-02-05 14:27

I have a two versions of my application layout, which are differs only in a few lines. Consider following example:

!!!    
%html
    %head
        # a lot of cod         


        
5条回答
  •  星月不相逢
    2021-02-05 15:25

    Okay, so I found the solution by myself:

    class ApplicationController < ActionController::Base
        layout 'layout'
        before_filter :set_constants
    
        def set_constants
            @flag = true
        end
    end
    

    And the template should be:

    !!!    
    %html
        %head
            # a lot of code here
    %body
        # some more code here
        - if @flag
            # variant 1
        - else
            # variant 2
    

提交回复
热议问题