gpt4 book ai didi

ruby-on-rails - Rails 中的布局文件夹是什么?

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

我知道 .html.erb 文件位于 app/views 或其子文件夹中。但是 app/views/layouts 文件夹在 Rails 中有什么用?

最佳答案

app/views/layouts 是 Rails 在其中查找 layouts 的文件夹。

来自 http://guides.rubyonrails.org/layouts_and_rendering.html#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.

什么是布局?

布局定义了 HTML 页面的环境。这是定义页面通用外观的地方。

RailsCasts 插曲 - All About Layouts - 虽然很老,但在这种情况下仍然非常有用。

关于ruby-on-rails - Rails 中的布局文件夹是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30880769/

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