migration error Paperclip in rails

0

Hello, every time I give the migration it throws me an error and it does not let me do the migration.

link

 gem "paperclip", "~> 5.0.0"
 gem "spring", group: :development

the gems that I have installed.

    
asked by juan gomez 22.08.2017 в 22:13
source

2 answers

0

What the error says is that you must specify in your migrations the version of Rails with which you are working; You do this by adding the bracketed version directly in the class you inherit from ActiveRecord::Migration ; for example, the error message shows how it would be done for Rails 4.2 :

class AddAttachmentAvatarToProductossnack < ActiveRecord::Migration[4.2]
  ...
end

In your case, that you are using version 5.1.1 then you would do the following:

class AddAttachmentAvatarToProductossnack < ActiveRecord::Migration[5.1]
  ...
end

The file you must edit is: db / migrate / 20170822195101_add_attachment_avatar_to_productossnack.rb ; which was generated when you executed the command:

$ rails generate paperclip productosnack avatar
    
answered by 22.08.2017 / 23:22
source
0

I still can not comment but helping you with your comment in the previous question would be the way to build the migration in this way.

class AddAttachmentAvatarToProductossnack < ActiveRecord::Migration[5.1]
  def up
    add_attachment :productossnack, :avatar
  end

  def down
    remove_attachment :productossnack, :avatar
  end
end

Command:

rails g migration AddAttachmentAvatarToProductossnack
    
answered by 23.08.2017 в 00:19