我在我的Users_controller:中定义了
layout "intro", only: [:new, :create]
下面是我的布局:Intro.html.haml
!!! 5
%html{lang:"en"}
%head
%title Intro
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body{style:"margin: 0"}
%header
= yield
%footer= debug(params)当我呈现一个调用intro作为布局的页面时,它会嵌套在我的application.html.haml文件中,这不是很好。
有没有办法避免这种不受欢迎的布局嵌套?
提前感谢!
发布于 2012-04-16 16:12:13
问题出在我的财务总监身上。我声明了如下所示的多个布局实例:
class UsersController < ApplicationController
layout "intro", only: [:new, :create]
layout "full_page", only: [:show]
...
end不要这样做!第二个声明将优先,您不会得到您想要的效果。
相反,如果您的布局只是特定于操作,只需在操作中声明它,如下所示:
def show
...
render layout: "full_page"
end或者,如果比较复杂,可以使用符号将处理过程推迟到运行时的方法,如下所示:
class UsersController < ApplicationController
layout :determine_layout
...
private
def determine_layout
@current_user.admin? ? "admin" : "normal"
end
endhttps://stackoverflow.com/questions/10165934
复制相似问题