gpt4 book ai didi

ruby-on-rails - ruby on rails 中的嵌套布局

转载 作者:行者123 更新时间:2023-12-04 00:06:24 25 4
gpt4 key购买 nike

我是 Rails 的新手,正在努力研究如何让嵌套布局工作;我假设它们有点像 .net 母版页?

我已关注 this guide我在我的布局目录中创建了一个 application.erb.html ,其中包含以下内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= @page_title or 'Page Title' %></title>
<%= stylesheet_link_tag 'layout' %>
<style type="text/css"><%= yield :stylesheets %></style>
</head>
<body>

<%= yield(:content) or yield %>

</body>
</html>

并将我现有的布局之一修改为:
<% content_for :stylesheets do %>

<% end -%>

<% content_for :content do %>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
<% end -%>

<% render :file => 'layouts/application' %>

当我在浏览器中转到我的一个 View 时,绝对没有渲染任何内容;当我查看源代码时,没有 html。

我确定我错过了一些基本的东西,有人可以指出吗?!

最佳答案

我已经找到了解决方案,尽管它不是 this article 中给出的

我已经更换了这条线

<% render :file => 'layouts/application' %>


<%= render :file => 'layouts/application' %>

我不确定这篇文章是否有误,或者我找到了错误的修复方法!请让我知道!

干杯

关于ruby-on-rails - ruby on rails 中的嵌套布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/741945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com