问题
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