我正在使用carrierwave的redactor_rails gem。有两个地方,我需要文字编辑器的图片上传,我想让每个编辑器不同的图片大小。
如果我使用版本,那么我有两个大小的每张图片,我不知道如何更改文本字段中的图片版本。
其主要思想是为redactor_rail_picture_uploader中的每个编辑器上传器运行自己的调整大小过程
我该怎么做?
发布于 2013-03-29 04:40:52
也许这不是最完美的方式,但它是有效的。
我已经制作了几个版本的上传文件在:redactor_rails_picture_uploader.rb
version :item_text do
process :resize_to_limit => [478, 478]
end
version :thumb do
process :resize_to_fill => [100, 100]
end创建了初始化器,并在那里重新定义了类RedactorRails::PicturesController的方法“create”。现在它保存了我通过' version‘参数传递给表单的版本。
RedactorRails::PicturesController.class_eval do
def create
@picture = RedactorRails::Picture.new
file = params[:file]
version = params[:version]
@picture.data = RedactorRails::Http.normalize_param(file, request)
if @picture.respond_to?(:user_id)
@picture.user = current_user
@picture.assetable = current_user
end
if @picture.save
if version
file_link = @picture.send(:url, version)
else
file_link = @picture.url
end
render :text => { :filelink => file_link }.to_json
else
render :nothing => true
end
end
end最后添加了隐藏输入,其中包含来自uploader的我想保存在此表单中的版本的值:
%input{:id => 'redactor_version', :value => 'item_text', :type => 'hidden'}就像这样。
https://stackoverflow.com/questions/14104773
复制相似问题