我正在尝试在像this这样的Rails中使用嵌套布局,但它无效。它显示一个空白页面。当我检查页面源代码时,它是空的。在日志中没有错:
Started GET "/" for 127.0.0.1 at 2018-03-19 16:36:30 -0300
Processing by ComingSoonController#index as HTML
Rendering coming_soon/index.html.erb within layouts/coming
Rendered coming_soon/index.html.erb within layouts/coming (5.1ms)
Rendering layouts/application.html.erb
Rendered layouts/application.html.erb (42.5ms)
控制器:
class ComingSoonController < ApplicationController
layout 'coming'
def index
end
end
视图/ comming_soon / index.html.erb
<% content_for :simple_content do %>
<div>
content here
</div>
<% end %>
视图/布局/ coming.html.erb
<% content_for :content do %>
teste
<%= yield(:simple_content) or yield %>
<% end %>
<% render :file => 'layouts/application' %>
视图/布局/ application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>some title</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_tag do %>
window.userSignedIn = <%= user_signed_in? %>;
<% end %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Exo+2" rel="stylesheet">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="theme-color" content="#000000">
<%= favicon_link_tag 'logo.ico' %>
</head>
<body>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<% if current_user %>
<%= link_to "Sair", destroy_user_session_path, method: :delete %>
<% else %>
<%= link_to "Registrar", new_user_registration_path %>
<%= link_to "Login", new_user_session_path %>
<% end %>
<%= yield(:content) %>
</body>
</html>
你知道发生了什么事吗?
谢谢
===================================
更新
解决方案:我必须更改&lt;%render:file =&gt; 'layouts / application'%&gt; by&lt;%= render template:'layouts / application'%&gt;