A systematic way to upgrade from attachment_fu to a carrier?

I am working on updating the application to Rails 3, and attachment_fu is broken, so I go to the carrier. Is there a systematic process that I can go through to move from attachment_fu to the carrier? Or a tutorial for this? Right now, I'm more interested in getting everything in the database right. I use the file system storage option for attachment_fu and carrier.

I found a module, UploaderFu from http://ruby.simapse.com/2011/03/migrate-attachmentfu-to-carrierwave.html that tells carrierwave to use the same directories and file names as attachment_fu. But this is not the whole answer, just part of it.

For example, in db, I have a UserImage model, with attributes :filename UserImage :width :user_id :height and :user_id . I added a column :user_avatar and the following to my model

 attr_accessible :user_avatar mount_uploader :user_avatar, UserAvatarUploader 

What exactly is stored in :user_avatar . Is this just a file name? or something different? I just need to write a hyphen to move the data in :filename (saved as "hello_world.png" ) to :user_avatar ? If in this case I should just use the original :filename instead of creating the :user_avatar column, right?

+4
source share
1 answer

The column on which you install the bootloader should store the "identifier" for the downloaded file. By default, this is simply the name of the file, but you can redefine it for almost everything except the record identifier (because you cannot know what it is after saving).

To override: in your loader class add this definition:

 def identifier # This is what gets put in the database column! model.created_on end 

In this example, I used the created_on attribute from the model. If you want to create your own storage engine, you should be able to uniquely identify files by this identifier, so be careful what you choose.

I would suggest renaming the column to describe the file being uploaded (for example, in the carrier example). Then you can always change the identifier from the file name to another.

+1
source

All Articles