rails4 paperclip3.0 对上传的图片进行裁剪,似乎裁剪的数据没有被重新处理,因为结果还是原来的整张图。
提交之后显示界面,图片仍然为整张图,没有被裁剪。
def update
    @user = User.find(params[:id])
    if @user.update_attributes(user_params)
        if params[:user][:photo].blank?
          redirect_to @user
        else
          render :action => 'crop'
        end
    else    
        render 'edit'
    end
end
  private 
def user_params
      params.require(:user).permit(:name, :email, :password, :phone,
                                   :password_confirmation, :photo )
end
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" ,:large => "500x500>"}, 
                              :processors => [:cropper],
                              :url => "/assets/products/:id/:style/:basename.:extension",  
                              :path => ":rails_root/public/assets/products/:id/:styl/:basename.:extension"
    attr_accessor :crop_x, :crop_y, :crop_w, :crop_h  
    after_update :reprocess_photo, :if => :cropping?
我考虑到可能是因为我采用的是健壮参数的形式传递数据,难道这样 crop_x,crop_Y 等数据没有被传递过去?但是不确定。 这是处理裁剪动作
module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
      else
        super
      end
    end
    def crop_command
      target = @attachment.instance
      if target.cropping?
        ["-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"]
      end
    end
  end
end