2013-11-27 40 views
1

有没有办法回滚特定的Rails回形针迁移?Rails回形针如何回滚只有一个附件

我想回滚只是一个迁移是avatar但这似乎并没有工作。

在Rails控制台中这样做的最好方法是什么?

回形针迁移

class AddAttachmentAvatarToUsers < ActiveRecord::Migration 
    def self.up 
    change_table :users do |t| 
     t.attachment :avatar 
    end 
    end 

    def self.down 
    drop_attached_file :users, :avatar 
    end 
end 
+0

你能在这里发表回形针迁移文件?您可能需要手动编辑“向下”才能获得所需内容 – portforwardpodcast

+0

@portforwardpodcast我粘贴了迁移 –

+0

这似乎应该起作用,所以我想你应该发布你的错误? – portforwardpodcast

回答

2

将这样的事情对你的工作?运行删除头像的新迁移。

class RemoveAvatarColumnsToUsers < ActiveRecord::Migration 
    def self.up 
    remove_attachment :users, :avatar 
    end 

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

希望这有助于

+0

你的意思是改变该文件的迁移? –

+0

我会在当前的'self_down'方法中使用'remove_attachment:users,:avatar'并执行回滚。如果你这样做,你有任何错误?顺便说一下,'drop_attached_file'是[老式语法](https://github.com/thoughtbot/paperclip#vintage-syntax) – user2262149