我得到的错误在我的部分_pins.html.erb中:
Pins #index中的NoMethodError - nil的未定义方法`avatar':NilClass 提取的来源(第4行):
3: <div class="avatar-position">
4: <%= image_tag pin.user.avatar.url(:thumb), class: "thumbsize" %>
5: </div>
图钉/索引视图(index.html.erb)有<%= render @pins %>
我通过索引控制器渲染它,所以在pins_controller.rb中我有:
def index
@pins = Pin.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @pins }
end
end
奇怪的是它在生产中运作良好。当我推送到heroku时,我没有错误,一切都很好。我最近更新了我的Mac OSX到10.8.5,但我不是,如果那是罪魁祸首?有一点不同的是,在开发过程中,我的图像资产(头像)在本地保存,而在生产中,它们通过回形针保存在亚马逊AWS上...任何想法?
答案 0 :(得分:2)
这里的局部变量pin
是什么?在<%= image_tag pin.user.avatar.url(:thumb), class: "thumbsize" %>
和部分pin has no user
中,avatar' for nil:NilClass
为pin.user
nil
所以做到这一点
<%= image_tag pin.user.avatar.url(:thumb), class: "thumbsize" unless pin.user.nil? %>