sách gpt4 ăn đã đi

ruby - 产量 :content doesn't show content_for :content

In lại 作者:数据小太阳 更新时间:2023-10-29 09:02:28 40 4
mua khóa gpt4 giày nike

我想我也有同样的问题。 Using multiple yields to insert content

我尝试了这个解决方案。我试过 <%= yield :content %>在我的 application.html.erb 中有 content_for :contentnăng suất里面,在我看来。但它不适用于我的应用程序。您能否就我的问题进行更多解释或提供示例场景?

里面的链接不能重新加载,所以我不会在我要显示的每个模板上使用 render partial。

我最近才开始学习 Rails,所以对我来说有点困惑。谢谢。

nhập mô tả hình ảnh ở đây

我试过了;这只是一个示例,稍后我会修复侧边栏的连接。

在我的 applicaion.html.erb 中



<đầu>
Clinks
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>




<%= render 'layouts/header' %>
<%= render 'layouts/sidebar' %>




<%=yield(:content) %>






在我的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]
kết thúc

然后在 menu_tables Controller 下的 _sidemenu.html.erb 中是链接的代码,因此来自侧边栏的每个链接都有不同的侧边菜单。

câu trả lời hay nhất

可能您需要告诉 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/

40 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress