file_column, magick and versions

Liquid error: undefined method `login' for nil:NilClass : January 9th, 2006

"Sebastian Kanthak's":http://www.kanthak.net handy "file_column":http://www.kanthak.net/opensource/file_column/ plugin is a great example of the power of plugins. However, if you manage your vendor/plugins directory using svn:externals and are using the awesome integrated RMagick capability, you may have noticed that it now uses directories to store the various defined versions rather than modifying the file name as with the 0.3.1 release. For example:
class Attachments < ActiveRecord::Base
    file_column :asset, :magick => { 
      :versions => { "thumb" => "50x50", "medium" => "640x480>" }
    }
end
With the 0.3.1 release any asset would have been saved like so: /path/to/file_thumb.jpg, /path/to/file_medium.jpg and then the original /path/to/file.jpg. When using the SVN version, the files are saved as: /path/to/thumb/file.jpg, /path/to/medium/file.jpg and /path/to/file.jpg. This obviously presents a major problem when you already have 5000 stored images and no (documented) way of migrating to the new naming scheme! A quick look at file_column.rb, line 45 -- aha! We can assign a real File object to the asset column and migrate that way. Backup your attachments first, then open up script/console and....
Attachment.find(:all).each do |a|
	a.asset = File.open(a.asset)
	a.save
end
Done!

3 Responses to “file_column, magick and versions”

  1. Carl Youngblood Says:
    Any chance of you giving a quick explanation on how to use svn:externals? I looked it up in the SVN book but am still a little hazy on how to set it up. I'm assuming it will allow me to place a link to an external svn project inside one of my own svn projects, so that running an svn update on my project will also cause the external linked project to get updated. My main question is, how can I check out an svn project into a subdir of my own svn project and cause it to be treated as an external? Thanks for the help.
  2. rainmkr Says:
    Carl, Assuming your entire project is under SVN, from $RAILS_ROOT type: svn propedit svn:externals vendor/plugins Each line represents an external, for example:
    file_column					  http://opensvn.csie.org/rails_file_column/plugins/file_column/trunk
    
    Checks out and updates file_column everytime you do an 'svn update'. Thanks for commenting.
  3. andré camargo Says:

    you saved my day! thanks a lot!!!

Leave a Reply

I am a human (check this)

Remember: escape your underscores \_ and indent code at least 4 spaces or incur the wrath of smartypants.