0

任何人可以帮助我,为什么我不能够加载特定的动作特定布局与我无法加载布局,而在轨渲染

render :layout => "application" 

application.html.erb目前在布局夹。 是我必须做一些布局设置?

我的代码是: -

class PageController < ApplicationController 
    layout false 
    def index1 
    render :layout => "application" 
    end 
end 
+0

请更好地解释错误,因为这应该起作用。你是否遇到错误,或者只是渲染没有布局? – Fallenhero

+0

@Fallenhero,它只是渲染没有布局。我不承认为什么。我的布局出现在布局文件夹中。我有这个谷歌,但没有找到任何答案。所以请帮助我为什么这个(render:layout =>“application”)不起作用。是我必须做一些设置? –

+0

@Fallenhero,其实我想添加特定的CSS与特定的布局。我在视图页面中使用了content_for,并在布局中输出其名称。我不明白它不从选择布局中的链接呈现CSS,或者不选择布局 –

回答

0

你可以试试这个多个动作:

layout 'layout_name', only: [:help , :contact_us] 

你可以试试这个单动作:

render layout: "layout_name" 

可以添加样式表标签的布局通过做这样的事情:

layout_name.erb

<%= stylesheet_link_tag 'layout_name' %> 
+0

,渲染布局:“layout_name”,它不是工作,我不知道为什么。我已经抓住了它,但没有找到任何答案。也有人提到使用“渲染布局:”layout_name“”渲染,但不幸的是它不工作 –

+0

从顶部删除布局false –

+0

没有它仍然不工作 –

0

也许你应该尝试:

render 'layouts/application' 

:layouts => "application" 

,因为有一个 “S” 来布局文件夹 希望它能帮助

0

试试这个:

class PageController < ApplicationController 
    layout false 
    layout 'application', only: [:index1] 
    def index1 

    end 
end