Ruby on rails 用户在模型中有2个图像附件。但是,在上传单个图像(即化身)后,它将同时替换这两个图像

Ruby on rails 用户在模型中有2个图像附件。但是,在上传单个图像(即化身)后,它将同时替换这两个图像,ruby-on-rails,image,heroku,amazon-s3,paperclip,Ruby On Rails,Image,Heroku,Amazon S3,Paperclip,因此,在MyRails应用程序中,我让用户能够将自己的化身图片和背景图像添加到他们的个人资料中 问题是,每当我上传化身图像时,它会同时显示化身和个人资料的背景。当我上传背景图像时,它会同时显示背景和化身图片,取代我设置的原始化身图片 在我的本地主机上,这很好。用户的简档可以显示化身图像和我设置的背景图像。但是,这个问题似乎只发生在heroku身上 你知道怎么解决这个问题吗 这是一个rails应用程序,我使用的是回形针和aws sdk 下面是我从用户#show中获得的一些代码 背景: <d

因此,在MyRails应用程序中,我让用户能够将自己的化身图片和背景图像添加到他们的个人资料中

问题是,每当我上传化身图像时,它会同时显示化身和个人资料的背景。当我上传背景图像时,它会同时显示背景和化身图片,取代我设置的原始化身图片

在我的本地主机上,这很好。用户的简档可以显示化身图像和我设置的背景图像。但是,这个问题似乎只发生在heroku身上

你知道怎么解决这个问题吗

这是一个rails应用程序,我使用的是回形针和aws sdk

下面是我从用户#show中获得的一些代码

背景:

 <div class="bg-dark lter nav-user pos-rlt" style="<%= show_user_bg %>"> 
这是来自用户的模型

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :avatar,         :tagline, :bio, :phone, :website, :city, :background
# attr_accessible :title, :body

validates_attachment :avatar, 
                    content_type: { content_type: ['image/jpeg',   'image/jpg', 'image/png', 'image/gif'] },
                    size: { less_than: 5.megabytes }
validates_attachment :background, 
          content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
          size: { less_than: 5.megabytes }            

has_many :projects
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" },  :default_url => "/images/:style/missing.png"
has_attached_file :background, :styles => { :medium => "300x300>", :thumb => "100x100>" },  :default_url => "/images/:style/missing.png"
end
这是表单中用来上传文件的代码

<%= f.input :avatar, label: "Upload Avatar", class: "btn btn-sm btn-info m-b-sm file-input" %>

<%= f.input :background, label: "Upload Background", class: "btn btn-sm btn-info m-b-sm file-input" %>

我没有在日志中发现错误。所以,我不是我做错了什么

提前感谢您提供的任何帮助。

我知道了

这真的很简单

以前,图像大小都是:中等。因此,出于某种原因,这导致用户化身图像也作为背景图像出现在配置文件中,反之亦然

当我将背景图像大小更改为:large并更改了尺寸时,它在配置文件上正确显示了这两个图像

has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :background, :styles => { :large => "400x600>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"

我通常有一个
/app/uploaders/
目录,文件名为
photo_uploader.rb
,它看起来像
#编码:utf-8类PhotoUploader
<%= f.input :avatar, label: "Upload Avatar", class: "btn btn-sm btn-info m-b-sm file-input" %>

<%= f.input :background, label: "Upload Background", class: "btn btn-sm btn-info m-b-sm file-input" %>
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :background, :styles => { :large => "400x600>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"