Posterous theme by Cory Watilo

idearisey

idearisey


paperclip processors and after_post_process

A few things to note when trying to process an uploaded file with paperclip:

  • The only way a post-processor will run is if a style is defined

class MyModel < ActiveRecord::Base

has_attached_file :mp3, :url => '/:class/:id/:style.:extension', :path => ':rails_root/assets/:class/:id_partition/:style.:extension', :whiny => true, :styles => { :text => { :do_something => true } }, :processors => [:my_processor]

# ...

end

  • To access the file after processing but before paperclip is finished, use the :after_process callback -- model instance attributes can be modified and will be saved automatically as part of the paperclip process

class MyModel < ActiveRecord::Base

# ...

after_post_process :do_one_more_thing

# ...

private

def do_one_more_thing

logger.info "MyModel [paperclip] after_post_process"

logger.info "MyModel [paperclip] file #{mp3.queued_for_write[:original].path}"

# Do more with the file

# Make model attribute changes as needed

# self.my_attribute = "x"

end

end

rails log rotation

No need to restart by following this post: http://www.hostingrails.com/401/What-is-the-best-practice-for-rails-log-rotat... #!/bin/sh mkdir /mnt/app/releases/mysite.com/log/archive -p tar czf "/mnt/app/releases/mysite.com/log/archive/`date +%Y%m%d`_production.tar.gz" -C / mnt/app/releases/mysite.com/log/production.log cat /dev/null > /mnt/app/releases/mysite.com/log/production.log find /mnt/app/releases/mysite.com/log/archive/* -mtime +180 -exec rm {} \;