honey
honey

Reputation: 1077

Paperclip attachment migration is not working

I have added 'paperclip' gem, bundled it, generated migration file as follows

class AddAvatarColumnsToUsers < ActiveRecord::Migration[6.0]
  def up
    add_attachment :users, :avatar
  end

  def down
    remove_attachment :users, :avatar
  end
end

When I running rake db:migrate, I am getting the following error

    Wrong number of arguments (given 3, expected 2)

ruby: 3.0.0

rails: 6.0.3.6

Upvotes: 1

Views: 494

Answers (1)

honey
honey

Reputation: 1077

Paperclip was deprecated and no one is maintaining it currently. In the newer version of ruby i.e., 3.0.0, attachment method performs differently. I have faced the lot of issues when migrating to 3.0.0. So I would recommend you to add the four columns explicitly as follows

  class AddAvatarColumnsToUsers < ActiveRecord::Migration[6.1]
    def up
       add_column :users, :avatar_file_name, :string
       add_column :users, :avatar_file_size, :integer
       add_column :users, :avatar_content_type, :string
       add_column :users, :avatar_updated_at, :datetime
    end

    def down
       remove_column :users, :avatar_file_name, :string
       remove_column :users, :avatar_file_size, :integer
       remove_column :users, :avatar_content_type, :string
       remove_column :users, :avatar_updated_at, :datetime
    end
  end

Upvotes: 2

Related Questions