The error I'm getting is in my partial _pins.html.erb:
NoMethodError in Pins#index -- undefined method `avatar' for nil:NilClass Extracted source (around line #4):
3: <div class="avatar-position">
4: <%= image_tag pin.user.avatar.url(:thumb), class: "thumbsize" %>
5: </div>
The pins/index view (index.html.erb) has <%= render @pins %>
I am rendering this via the index controller, so in pins_controller.rb I have:
def index
@pins = Pin.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @pins }
end
end
The weird thing is it works fine in production. When I push to heroku, I get no errors and everything renders fine. I did recently update my Mac OSX to 10.8.5, but I am not if that was the culprit? One thing that is different is that in development, my image assets (avatars) are saved locally, while in production they are saved on amazons AWS with paperclip... Any ideas?
what is the local variable pin
here ? in <%= image_tag pin.user.avatar.url(:thumb), class: "thumbsize" %>
and some of the pin has no user
so you gotavatar' for nil:NilClass
as pin.user
is nil
so make it
<%= image_tag pin.user.avatar.url(:thumb), class: "thumbsize" unless pin.user.nil? %>