Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cedricdekimpe/1159037 to your computer and use it in GitHub Desktop.
Save cedricdekimpe/1159037 to your computer and use it in GitHub Desktop.
libpaperclip_processorsrotator.rb:6 : rotate_command to array to avoid "Can't convert String into Array" error
class GalleryImagesController < ApplicationController
def rotate
@image = GalleryImage.find(params[:id])
rotation = params[:deg].to_f
rotation ||= 90 # Optional, otherwise, check for nil!
@image.rotate!(rotation)
flash[:notice] = "The image has been rotated"
end
end
class GalleryImage < ActiveRecord::Base
belongs_to :property
has_attached_file :image, :styles => {:small => "300x300#",
:medium => "575x420>",
:small_thumb => "95x95#",
:thumb => "100x100#",
:large => "550x550>",
:featured => "296x477!"},
:default_style => :small,
:processors => [:rotator]
attr_accessor :rotation_degrees, :rotate
before_create :set_defaults
def rotate!(degrees = 90)
self.rotation += degrees
self.rotation -= 360 if self.rotation >= 360
self.rotation += 360 if self.rotation <= -360
self.rotate = true
self.image.reprocess!
self.save
end
def rotating?
!self.rotation.nil? and self.rotate
end
private
def set_defaults
self.rotation ||= 0
end
end
module Paperclip
class Rotator < Thumbnail
def transformation_command
if rotate_command
# having the "super" at the end ensures that your thumbnails are allways "inside the limits of your styles"
[rotate_command] + super
else
super
end
end
def rotate_command
target = @attachment.instance
if target.rotating?
" -rotate #{target.rotation}"
end
end
end
end
module Paperclip
class Rotator < Thumbnail
def transformation_command
if rotate_command
# having the "super" at the end ensures that your thumbnails are allways "inside the limits of your styles"
rotate_command + super
else
super
end
end
def rotate_command
target = @attachment.instance
if target.rotating?
" -rotate #{target.rotation}"
end
end
end
end
@dheza
Copy link

dheza commented Dec 11, 2012

Hello, I'm trying to use this sample, but I'm receveing the following message:
NoMethodError (undefined method rotate!' for #<Paperclip::Attachment:0x5f60100>): app/controllers/master/visits_controller.rb:1053:inrotate_image_event'

Please Help-me, I'm newer in rails

@qmclaugh
Copy link

    super + ([] << rotate_command)

(hack)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment