【发布时间】:2020-07-17 18:02:32
【问题描述】:
这是我目前在我的 Vision 模型中拥有的:
has_one_attached :image
belongs_to :user
def featured_image_url
if self.image.attachment
self.image.attachment.service_url
end
end
end
在我的 Vision 控制器中:
def create
@vision = current_user&.visions.create(vision_params)
render :create, status: :created
end
def vision_params
params.permit(:description, :image)
end
在 _vision.json.jbuilder 中:
json.call(
vision,
:id,
:description,
:created_at,
:updated_at
)
json.image_url polymorphic_url(vision.image)
我正在使用 Amazon S3 进行图像存储。如何更改我的代码以上传多个图像文件?
还请记住,我的数据库中有现有数据,我在其中获取每个视觉一个图像的图像 URL。如何在不影响现有数据库的情况下进行更改?
提前谢谢你?????????
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 rails-activestorage