【发布时间】:2017-10-07 18:33:21
【问题描述】:
我有一个使用 Carrierwave 的标准图片上传器。我也在使用 Postgres。所以这就是我的迁移将图像添加为 JSON 的样子:
class AddImagesToListings < ActiveRecord::Migration[5.1]
def change
add_column :listings, :images, :json
remove_column :listings, :image
end
end
我想让 images[0] 总是有一些图像,但似乎 Carrierwave 文档仅涵盖单个文件上传的内容。现在,这是我的 default_url 方法:
def default_url(*args)
ActionController::Base.helpers.asset_path("default/" + ["default.jpg"].compact.join('_'))
end
这在我只有 :image 时有效,但现在不行了。有没有办法为 images[0] 设置默认值,以便我为我拥有的每个列表获得有效的 images[0].url(不管用户是否将图像添加到列表中)?
【问题讨论】:
标签: ruby-on-rails json carrierwave