Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails3 get current layout name inside view

I have the answer for the Rails 2.X but not for Rails 3. How can I read the name of a current layout rendered inside a view.

My Rails2 question: Rails Layout name inside view

Thx.

like image 302
xpepermint Avatar asked Jul 24 '10 19:07

xpepermint


1 Answers

in rails 5

This works for me:

def current_layout
  layout = controller.class.send(:_layout)
  if layout.nil?
    default_layout
  elsif layout.instance_of? String or layout.instance_of? Symbol
    layout
  else
    File.basename(layout.identifier).split('.').first
  end
end
like image 164
Ebrahim El Gaml Avatar answered Oct 04 '22 02:10

Ebrahim El Gaml