[英]How can I pass more than 2 arguments to partial?
我想傳遞2個參數,例如topic
和icon_photo
。
我怎樣才能做到這一點?
未定義的方法“ icon_photo?”
我在以下代碼中收到此錯誤。
視圖
<div class="Topic">
<% @community.topics.each do |topic| %>
<%= render 'topics/topic', :topic => topic, :icon_photo => topic.user.profile.avatar %>
<% end %>
</div>
您可以傳遞本地哈希值:
<div class="Topic">
<% @community.topics.each do |topic| %>
<%= render 'topics/topic', locals: {topic: topic, icon_photo: topic.user.profile.avatar, etc: 'blabla' } %>
<% end %>
</div>
在此處查看一些文檔 : http : //www.tutorialspoint.com/ruby-on-rails/rails-render.htm
可能會有一點改進 ,您可以像這樣渲染您的收藏集:
<div class="Topic">
<%= render partial: 'topics/topic', collection: @community.topics %>
</div>
# in your partial topics/_topic.html.erb:
<% icon_photo = topic.user.profile.avatar %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.