Rails 中的布局文件夹有什么用?

What's the layouts folder for in Rails?

我了解 .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 - 虽然很老,但在这方面仍然非常有用。

rails 框架中的布局是非常重要的文件夹,您的应用程序的主要布局在此处定义为 application.html.erb 并且所有视图都在此处使用 <% yield %>

生成