如何使用Ruby on Rails中的回形针创建模型具有无限图像?

jun*_*Man 1 ruby model ruby-on-rails paperclip

我有一个具有头像的用户模型.Paperclip用于允许图像上传.但是,我希望用户能够上传尽可能多的图像(无限制).如何修改我的模型以允许此类行为?用户模型如下所示:

class Model < ApplicationRecord
  has_attached_file :pic, styles: { medium: "420×633!", thumb: "100x100#" }, default_url: "/images/:style/missing.png"
  validates_attachment_content_type :pic, content_type: /\Aimage\/.*\z/
  has_many :reviews, dependent: :destroy 
Run Code Online (Sandbox Code Playgroud)

提前致谢 !

Vis*_*hal 6

您可以photos在单独的模型中为用户存储(如果您将其称为),并在User模型中为其添加关联:

命令行

rails g paperclip photo pic
Run Code Online (Sandbox Code Playgroud)

应用程序/模型/ user.rb

has_many :photos, dependent: :destroy
Run Code Online (Sandbox Code Playgroud)

应用程序/模型/ photo.rb

belongs_to :user
has_attached_file :pic, styles: { medium: "420×633!", thumb: "100x100#" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :pic, content_type: /\Aimage\/.*\z/
Run Code Online (Sandbox Code Playgroud)