gpt4 book ai didi

ruby-on-rails - 为什么 Rails 中的部分代码以下划线开头?

转载 作者:行者123 更新时间:2023-12-03 07:23:03 25 4
gpt4 key购买 nike

我不确定这是否符合惯例,但我一直在学习 Hartl 的 Rails 教程,我注意到他创建的所有部分文件都带有前导下划线。例如_user.html.erb。这是部分工作所必需的,还是一种风格选择?

最佳答案

这是部分工作所必需的。来自 official Rails guide :

3.4.1 Naming Partials

To render a partial as part of a view, you use the render method within the view:

<%= render "menu" %>

This will render a file named _menu.html.erb at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:

关于ruby-on-rails - 为什么 Rails 中的部分代码以下划线开头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25353108/

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