- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我想我也有同样的问题。 Using multiple yields to insert content
我尝试了这个解决方案。我试过 <%= yield :content %>
在我的 application.html.erb 中有 content_for :content
和 yield
里面,在我看来。但它不适用于我的应用程序。您能否就我的问题进行更多解释或提供示例场景?
里面的链接不能重新加载,所以我不会在我要显示的每个模板上使用 render partial。
我最近才开始学习 Rails,所以对我来说有点困惑。谢谢。
我试过了;这只是一个示例,稍后我会修复侧边栏的连接。
在我的 applicaion.html.erb 中
<!DOCTYPE html>
<html>
<head>
<title>Clinks</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<section id="container" >
<%= render 'layouts/header' %>
<%= render 'layouts/sidebar' %>
<section id="main-content">
<section class="wrapper">
<div class="row">
<!-- %= yield % -->
<%=yield(:content) %>
</div><!--/row -->
</section><!--/wrapper -->
</section><!--/main-content -->
</section><!--/container -->
</body>
</html>
在我的menu_tables.html.erb里面layouts
文件夹。
<% content_for(:content) do %>
<%= render 'menu_tables/sidemenu' %>
<%= yield %>
<% end %>
<%= render template: "layouts/application" %>
在我的 routes.rb 中
Rails.application.routes.draw do
root :to => 'pages#home'
resources :menu_tables, except: [:show]
end
然后在 menu_tables Controller 下的 _sidemenu.html.erb 中是链接的代码,因此来自侧边栏的每个链接都有不同的侧边菜单。
最佳答案
可能您需要告诉 Controller 使用layout 'menu'
。在链接中,您提供了匹配的 Controller 名称和布局,因此它“神奇地”工作了。参见 guides :
2.2.14 Finding Layouts
To find the current layout, Rails first looks for a file in app/views/layouts with the same base name as the controller. For example, rendering actions from the PhotosController class will use app/views/layouts/photos.html.erb (or app/views/layouts/photos.builder). If there is no such controller-specific layout, Rails will use app/views/layouts/application.html.erb or app/views/layouts/application.builder. If there is no .erb layout, Rails will use a .builder layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.
(注意:您可以检查日志中使用的布局,查找类似于 Rendered menu_items/index.html.erb within layouts/application
的行)
关于ruby - 产量 :content doesn't show content_for :content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32001284/
使用 Python 3.4,我在此处得到 SyntaxError: invalid syntax: >>> xlist = [1,2,3,4,5] >>> [yield(x) for x in xli
在这篇文章 ( http://blogs.msdn.com/oldnewthing/archive/2008/08/13/8854601.aspx ) 中,有一个关于迭代器的流行问题和一个关于极端情况
在 Ruby 中,yield 关键字用于让出执行 block 的闭包。 这个关键字在 Python 语言中有何不同? 最佳答案 在 ruby 中,yield 是用于调用匿名函数的快捷方式。 Rub
这个问题在这里已经有了答案: check if function is a generator (13 个答案) 关闭 7 年前。 检查函数是否为生成器的可靠方法是什么,例如: let fn = f
jquery 中是否可以产生变量?我想在部分 View 中设置一个变量,根据该变量我将某个菜单项设置为事件状态。 我有一个菜单,我想在其中产生像这样的事件项目(在我的主布局 View 中): func
问题 是否可以将 yielding pytest fixtures(用于设置和拆卸)作为参数传递给测试函数? 上下文 我正在测试一个对象,该对象从单个目录中的文件读取数据/向文件写入数据。该目录的路径
我刚刚开始使用 Ruby,我在 Bloc 的类(class)中已经走了很长一段路,但现在我被困在与 yield 和 blocks 有关的练习上(我发现这是迄今为止最难掌握的概念说到学习 ruby
我一直在寻找这一点,但我还没有得到任何关于它的信息!。 我看了很多关于“ yield 返回”的视频和红色文章,我想我对它有更好的理解,但有一点我无法理解 我应该使用 yield return 的正确接
UPDATE(反映最先进的知识水平)状态:2017-05-12 进行此更新的原因是,当我问这个问题时,我并不知道我发现了有关Python3如何“在幕后”工作的信息。 从所有得出的结论是: 如果您为迭代
我正在尝试在 Atmel Studio 7 中为 Arduino 编写代码。为了使其与 Arduino IDE 相似,我正在尝试调整其库。 但是我已经被 delay() 阻止了,它使用了 yield(
我正在构建一个简单的 C++ 服务器,我在其中通过 POST 请求接收图像,将其发送到 GPU 进行处理,一旦我从 GPU 获得结果,就发回响应。 为了能够处理许多同时连接(并学习新的东西),我正在使
我想生成从每片叶子到树根的所有路径。我想用生成器来做,以节省内存(树可以很大)。这是我的代码: def paths(self, acc=[]): if self.is_leaf():
假设我有以下代码(缩小上下文以限制问题范围) public static IEnumerable GetThemColors(){ var ids = GetThePrimaryIds();
我想我也有同样的问题。 Using multiple yields to insert content 我尝试了这个解决方案。我试过 在我的 application.html.erb 中有 conte
我熟悉 yield 以返回值,这主要归功于 this question 但是当它在赋值的右边时,yield 会做什么呢? @coroutine def protocol(target=None):
function * d1 (p) { p-=1; yield p; p-=2; yield p; } var g=d1 (9); var h; console.l
以下代码在 golang 中实现了 yield 模式。作为一项实验,我正在实现一个all permutations 生成器。但是,当我将 slice A 返回到 channel 时,如果我不创建数组的
Node.js 现在有生成器。 我的理解是,生成器可用于编写看起来更加线性的代码,并避免回调 hell 和末日风格编码的金字塔。 所以到目前为止,我的理解是,在生成器内部,代码会一直执行,直到它到达“
我遇到的问题真的很奇怪。由于某种原因,我的 catch block 中的 put 没有在下面执行。这是我的传奇: function* postLoginFormSaga(action) { l
假设我只想快速使以下方法异步运行: ResultType SynchronousCode(ParamType x) { return SomeLongRunningWebRequest(x)
我是一名优秀的程序员,十分优秀!