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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top