将一个 table 中的数据添加到 Rails 中的附件
include data from one table to attachment in Rails
我需要在帖子列表中显示来自用户的头像,在 "show" 头像作品中。
控制器
def index
@posts = Post.all
@user = User.find(@post.user_id)
end
查看
index.html.haml
= render @posts
_post.html.haml
= @user.avatar.url(:thumb)
= post.title
= post.body
您需要 image_tag 来显示图像
将 = @user.avatar.url(:thumb)
更改为 = image_tag @user.avatar.url(:thumb)
我只需要使用= image_tag post.user.avatar.url(:thumb)
我需要在帖子列表中显示来自用户的头像,在 "show" 头像作品中。
控制器
def index
@posts = Post.all
@user = User.find(@post.user_id)
end
查看 index.html.haml
= render @posts
_post.html.haml
= @user.avatar.url(:thumb)
= post.title
= post.body
您需要 image_tag 来显示图像
将 = @user.avatar.url(:thumb)
更改为 = image_tag @user.avatar.url(:thumb)
我只需要使用= image_tag post.user.avatar.url(:thumb)