Read more

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

Arne Hartherz
October 27, 2010Software engineer at makandra GmbH

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
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

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

File.basename(response.layout)
=> "admin"
Posted by Arne Hartherz to makandra dev (2010-10-27 10:06)