开发者

Spree, Ruby On Rails. Question about the employment of the "yield" function

While reading the spree source code via the official code repository on Github, https://github.com/spree/spree. I couldn't help but notice a strange (at least the first time I see it) usage of the function "yield" on the main loading page of the demo site, as in https://github.com/spree/spree/blob/master/core/app/views/layouts/spree_application.html.erb

The unnamed yield in the body of the page intrigues me, what makes it automatically "yield" the content of the following page: https://github.com/spree/spree/blob/master/core/app/views/shared/_products.html.erb

In other words what decides on what to be render while using an unnamed yield.

Any clarification will be highly appreciat开发者_StackOverflow社区ed.


spree_application.html.erb is a main application layout page. This will have all the design common to application/large part of application (One place to make changes sitewide).

the unnamed yield will place the content of view which is related to current request.

You must have noticed this when you visited home page. Which is products#index (Products controller and view index). root :to => 'products#index' (Reference).

If you check (product#index view), it renders partials from shared/_product

<%= render "shared/products", :products => @products, :taxon => @taxon %>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜