partial render for rails

3.4 Using Partials

Partial templates – usually just called “partials” – are another device for breaking apart the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.

3.4.1 Naming Partials

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

<%= 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:

<%= render "shared/menu" %>

That code will pull in the partial from app/views/shared/_menu.html.erb.

 

http://guides.rubyonrails.org/layouts_and_rendering.html

原文地址:https://www.cnblogs.com/lexus/p/1863877.html