從Rails的API上PartialRender:
再現默認情況下
如果你不打算使用任何像集合或佈局的選項,您還可以使用速記渲染部分的默認渲染。
例子:
# Instead of <%= render partial: "account" %>
<%= render "account" %>
# Instead of <%= render partial: "account", locals: { account: @buyer } %>
<%= render "account", account: @buyer %>
# @account.to_partial_path returns 'accounts/account', so it can be used to replace:
# <%= render partial: "accounts/account", locals: { account: @account} %>
<%= render @account %>
# @posts is an array of Post instances, so every post record returns 'posts/post' on `to_partial_path`,
# that's why we can replace:
# <%= render partial: "posts/post", collection: @posts %>
<%= render @posts %>
所以,你可以使用通過局部變量size
呈現如下:
<%= render @users, size: 50 %>
,然後用它在_user.html.erb
部分:
<li>
<%= gravatar_for user, size: size %>
<%= link_to user.name, user %>
</li>
請注意, size: size
相當於:size => size
。
感謝@jamesw,但圖像還是大小52.是不是因爲我的部分尺寸設置爲52? – dopplesoldner 2013-04-26 18:06:29
實際上,您正在覆蓋以前的尺寸值。 – 2013-04-26 21:46:20
我也會在沒有'collection'屬性的情況下工作 – ImranNaqvi 2015-11-26 11:24:31