Question

I'm trying to render a User's Avatar on a Show Page.

Scenario: User creates Account and set's Avatar. Avatar is displayed correctly oh his Profile page(stretchy but its there). But on another Page is says

undefined method `avatar' for nil:NilClass

the code is

<%= image_tag @user.avatar.url(:avatar), class: "size48" %> 

Edit

In my Views folder the image get's rendered only on the USERS folder, on the other folders im getting this error.

UserModel -> http://pastebin.com/pdTTLgrw

Était-ce utile?

La solution

@user variable is nil. There should be @user = User.find(params[:id]) in the controller action of the page you're trying to load.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top