रेल एपीआई से 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
के बराबर है।
स्रोत
2014-03-14 19:26:29
धन्यवाद @jamesw, लेकिन छवियाँ हैं अभी भी आकार 52. इसकी वजह है मेरे पास आकार आंशिक रूप से 52 तक सेट है? – dopplesoldner
हां वास्तव में, आप आकार के पिछले मान को ओवरराइड कर रहे हैं। –
मैं 'संग्रह' विशेषता – ImranNaqvi