Shpigford
Shpigford

Reputation: 25378

Rails 3: How to get the name of the current layout?

In my controller I have:

render :layout => 'mobile'

In my view I want to be able to get the name of the layout, in this case "mobile".

I don't need the controller or action name...just the name of the layout.

I'm using Rails 3.0.6.

Upvotes: 5

Views: 5177

Answers (2)

Marco Godínez
Marco Godínez

Reputation: 3470

I was late, but try this:

controller.send(:_layout).virtual_path.name

Tested in Rails 3.2

Upvotes: 11

tmaximini
tmaximini

Reputation: 8503

why you dont make an variable in your controller:

@layout = 'mobile'
render :layout => @layout

then you can access @layout in your view

Upvotes: 0

Related Questions