Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有多个视图,但它们应该共享相同的部分(例如页脚和广告栏),这些共享的部分应该去哪里?
我会在视图中创建一个共享文件夹并将我所有的共享部分放入其中。您可以像这样调用部分:
<%= render 'shared/partialname' %>
创建部分文件时,您必须在文件名前加上下划线。
像footer inside a layout folder -> _footer.html.erb
footer inside a layout folder -> _footer.html.erb
然后您必须使用以下语句在特定位置指定:
<%= render 'layout/footer' %>