Get the current layout's name in a view or partial

Updated . Posted . Visible to the public. Deprecated.

This was valid for ancient Rails versions. It won't work on current Railses.

This returns the name (including path) of your current layout:

response.layout
=> "layouts/admin" # inside views that are using the 'admin' layout

You most likely do not need the full path, so go ahead and do this:

File.basename(response.layout)
=> "admin"
Profile picture of Arne Hartherz
Arne Hartherz
Last edit
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2010-10-27 08:06)