Rails 4 - Name Of Current Layout?

后端 未结 3 667
我在风中等你
我在风中等你 2021-02-14 01:20

I\'ve found numerous resources for Rails 3, but none for Rails 4:


In an effort to keep things DRY, we have a method which defines some meta tags. I\'d like to incl

3条回答
  •  心在旅途
    2021-02-14 01:50

    In Rails 5, the code is:

    controller.send :_layout, ["some_string_here"]
    

    I don't know why it needs a string in the array but that's what got it working for me. Our helper file looks as follows:

    def current_layout
      layout = controller.send :_layout, ["test"]
      return layout.inspect.split("/").last.gsub(/.haml/,"")
    end
    

提交回复
热议问题