Skip to main content
 首页 » 编程设计

ruby-on-rails之rails 3 : How to get the name of the current layout

2024年06月20日20zengkefu

在我的 Controller 中,我有:

render :layout => 'mobile' 

在我看来,我希望能够获取布局的名称,在本例中为“mobile”。

我不需要 Controller 或操作名称...只需布局名称。

我使用的是 Rails 3.0.6。

请您参考如下方法:

我迟到了,但试试这个:

controller.send(:_layout).virtual_path.name

在 Rails 3.2 中测试