“render @collection”是什么意思?做?

发布于 2024-08-27 16:34:09 字数 342 浏览 10 评论 0原文

我试图通过查看示例应用程序来更好地学习 Rails,同时查看 railscasts.com 源代码的这一行,我注意到它是这样做的:

<div class="episodes">
    <%= render @episodes %>
  </div>

这里到底发生了什么?为什么渲染函数中没有记录这一点?或者是吗?

I'm trying to learn Rails better by looking at example applications, and while looking at this line of the source of railscasts.com, I noticed it does this:

<div class="episodes">
    <%= render @episodes %>
  </div>

What exactly is going on here? Why isn't this documented on the render function? Or is it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云雾 2024-09-03 16:34:09

这是一个方便的快捷方式,

<%= render :partial => "episode", :collection => @episodes %>

这是另一种方式

<% for episode in @episodes do %>
  <%= render :partial => "episode", :locals => { :episode => episode }
<% end %>

,它的作用非常明显:)

希望这是有道理的:)

顺便说一句,我也找不到这方面的文档,这真的很令人惊讶。

This is a handy shortcut for doing

<%= render :partial => "episode", :collection => @episodes %>

which is another way of doing

<% for episode in @episodes do %>
  <%= render :partial => "episode", :locals => { :episode => episode }
<% end %>

which is pretty obvious in what it does :)

Hope that makes sense :)

btw it's really surprising I couldn't find the docs for this too.

一杆小烟枪 2024-09-03 16:34:09

的简写

这是render :partial => “剧集”,:集合=> @episodes

上面的表单记录在 Rails API 文档 中的 render (ActionController ::基础)。据我所知,除了 Rails 指南 之外,速记形式没有记录。

This is shorthand for

render :partial => "episode", :collection => @episodes

The form above is documented in the Rails API docs under render (ActionController::Base). The shorthand form is not documented as far as I can see except in the Rails Guides.

花开半夏魅人心 2024-09-03 16:34:09

这是一个新的快捷方式:

<%= render @episodes %>

# equivalent to
<%= render :partial => 'episode', :collection => @episodes %>

您还可以对单个项目执行快捷方式

<%= render 'comment', comment => @comment  %>

# equivalent to
<%= render :partial => 'comment', :locals => {:comment => @comment} %>

This is a new shortcut:

<%= render @episodes %>

# equivalent to
<%= render :partial => 'episode', :collection => @episodes %>

You can also do shortcuts with single items

<%= render 'comment', comment => @comment  %>

# equivalent to
<%= render :partial => 'comment', :locals => {:comment => @comment} %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文