redactor rails和carrierwave - 图片大小

kon*_*ave 5 ruby-on-rails redactor

我正在使用带有carrierwave的redactor_rails gem.有两个地方我需要文本编辑器和图片上传,我想为每个编辑器制作不同的图片大小.

如果我使用版本,那么每张图片都有两种尺寸,我不知道如何在文本字段中更改图片版本.

主要思想是在redactor_rail_picture_uploader中为每个编辑器上传器运行它自己的resize进程

我怎么做?

kon*_*ave 2

也许这不是完美的方法,但它确实有效。

我已经在以下位置制作了上传文件的多个版本: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
Run Code Online (Sandbox Code Playgroud)

在那里创建了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
Run Code Online (Sandbox Code Playgroud)

最后添加了隐藏输入,其中包含来自上传者的版本值,我想以这种形式保存:

%input{:id => 'redactor_version', :value => 'item_text', :type => 'hidden'}
Run Code Online (Sandbox Code Playgroud)

像这样的东西。