Rails Active Storage not display @user.banner_image [duplicate]

随声附和 提交于 2019-12-13 03:56:18

问题


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

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


回答1:


It shoud be:

.profile-header
  = image_tag url_for(@user.banner_image)



回答2:


You must tell Active Storage which service to use by setting Rails.application.config.active_storage.service

Store files locally

config.active_storage.service = :local


来源:https://stackoverflow.com/questions/58002952/rails-active-storage-not-display-user-banner-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!