Failed on Migration using Paperclip on Rails

81 Views Asked by At

I am trying to install Paperclip using Rails 6.1

I ran this command : rails g paperclip Model image

And i got this migration :

class AddAttachmentImageToExercises < ActiveRecord::Migration
  def self.up
    change_table :exercises do |t|
      t.attachment :image
    end
  end

  def self.down
    remove_attachment :exercises, :image
  end
end

But i got this error :

Caused by:
StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for:

Then i put class AddAttachmentImageToExercises < ActiveRecord::Migration[6.1] I got this error :

ArgumentError: wrong number of arguments (given 3, expected 2)

What should i do? Thank You

1

There are 1 best solutions below

2
David Aldridge On

Shouldn't up and down be instance methods, not class methods?

So removing the "self." might fix this?

class AddAttachmentImageToExercises < ActiveRecord::Migration[6.1]
  def up
    change_table :exercises do |t|
      t.attachment :image
    end
  end

  def down
    remove_attachment :exercises, :image
  end
end