的确,@community有4个标签,因此它不应该返回零错误。
但是在这种情况下,它会返回像这样的nil错误。为什么以及如何修复?为什么在这种情况下我得到零错误?
ActionView::Template::Error (undefined method `+' for nil:NilClass):
我的代码
<% @community.tags.each do |tag| %><% tag_strings = tag_strings + tag.name + "," %><% end %>
<%= render 'layouts/twitter', :tag => tag_strings + @community.community_name %>
你初始化'tag_strings'给'” “在这个代码之前? – Dogbert 2013-02-22 13:21:20
@DOgbert号我没有 – HUSTEN 2013-02-22 13:21:48
那么这就是你应该做的:) – Dogbert 2013-02-22 13:24:15