Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing column names with paperclip gem

Is there a way to change the column names that paperclip uses when generating its database migration? For example, currently a paperclip migration looks like this:

class AddAvatarColumnsToUsers < ActiveRecord::Migration
  def self.up
    add_attachment :users, :avatar
  end

  def self.down
    remove_attachment :users, :avatar
  end
end

And it generates the following in the database:

avatar_file_name
avatar_file_size
avatar_content_type
avatar_updated_at

Ideally I'd like to change the avatar_file_name to correspond to a column in the database called "content". Is this possible?

like image 545
bswinnerton Avatar asked Dec 12 '12 05:12

bswinnerton


1 Answers

Renaming columns, to something else than <attachment>_<attribute> will not work in Paperclip.

It mandatorily needs the following 4 attributes for each attachment in the model:

  • <attachment>_file_name
  • <attachment>_file_size
  • <attachment>_content_type
  • <attachment>_updated_at

Check this post out for a debate on why following a <attachment>_url approach might be better than having a separate model for attachment (<attachment>.url): Paperclip and Inheritance (STI)

like image 159
Subhash Avatar answered Oct 15 '22 21:10

Subhash