我想传递两个参数,例如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>
答案 0 :(得分:7)
您可以传递本地哈希:
<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
稍微改进可以是mabe,您可以像这样呈现您的收藏:
<div class="Topic">
<%= render partial: 'topics/topic', collection: @community.topics %>
</div>
# in your partial topics/_topic.html.erb:
<% icon_photo = topic.user.profile.avatar %>