Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Layout name inside view

How can I print out the name of current layout in a view?

Example

puts controller.current_layout

Thx

like image 496
xpepermint Avatar asked Dec 01 '22 05:12

xpepermint


2 Answers

This works with Rails 3.0.7:

controller.send :_layout

Obviously, it's a private method, so use at your own risk.

like image 95
Isaac Dudek Avatar answered Dec 04 '22 05:12

Isaac Dudek


This works for me: response.layout

UPDATE: True, response.layout does not work in rails3+ thus I usually define a @layout_name variable inside each layout.

Example of application.html.haml

- @layout_name = 'application'
!!! Strict
%html
...
like image 36
xpepermint Avatar answered Dec 04 '22 05:12

xpepermint