简体   繁体   English

渲染回形针头像

[英]Render Paperclip Avatar

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). 阿凡达(Avatar)正确显示在他的“个人资料”页面上(可伸缩,但在那里)。 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. 在我的Views文件夹中,仅在USERS文件夹上呈现图像,而在其他文件夹上则出现此错误。

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

@user variable is nil . @user变量为nil There should be @user = User.find(params[:id]) in the controller action of the page you're trying to load. 您要加载的页面的控制器操作中应该有@user = User.find(params[:id])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM