Rails Active Storage 不显示@user.banner_image [英] Rails Active Storage not display @user.banner_image

查看:56
本文介绍了Rails Active Storage 不显示@user.banner_image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近一直在玩 rails active storage 并遇到了一个问题.

So I've been playing with rails active storage lately and came across an issue.

user.rb

class User < ApplicationRecord
  has_one_attached :banner_image
end

<小时>

show.html.haml

.profile-header
  = @user.banner_image

作为回报,我收到此错误:

in return i get this error:

Can't resolve image into URL: to_model delegated to attachment, but attachment is nil
Extracted source (around line #2):

.profile-header
  = image_tag @user.banner_image

.listings
  - @listings.each do |listing|
    .box

我做错了什么?顺便说一下,我允许在用户控制器中使用 banner_image.我安装了活动存储.

What am I doing wrong? I permitted the banner_image in the user controller by the way. and i have active storage installed.

推荐答案

你必须通过设置Rails.application.config.active_storage.service

本地存储文件

config.active_storage.service = :local

这篇关于Rails Active Storage 不显示@user.banner_image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆