【发布时间】:2015-11-07 04:35:56
【问题描述】:
我想我也有同样的问题。 Using multiple yields to insert content
我尝试了解决方案。在我看来,我试图在我的 application.html.erb 中添加 <%= yield :content %> 并在里面添加 content_for :content 和 yield。但它不适用于我的应用程序。您能否就我的问题进行更多解释或提供示例场景?
里面的链接不能重新加载,所以我不会在我要显示的每个模板上使用渲染部分。
我最近才开始学习 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>
在 layouts 文件夹内的 menu_tables.html.erb 中。
<% 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控制器下的_sidemenu.html.erb中是链接的代码,所以侧边栏的每个链接都有不同的sidemenu。
【问题讨论】:
标签: ruby ruby-on-rails-4 yield content-for