{"action":"closed","issue":{"url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1773","repository_url":"https://api.github.com/repos/thoughtbot/paperclip","labels_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1773/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1773/comments","events_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/1773/events","html_url":"https://github.com/thoughtbot/paperclip/issues/1773","id":58305588,"number":1773,"title":"Duplicating a dirty record breaks assignment","user":{"login":"brendon","id":81871,"avatar_url":"https://avatars3.githubusercontent.com/u/81871?v=4","gravatar_id":"","url":"https://api.github.com/users/brendon","html_url":"https://github.com/brendon","followers_url":"https://api.github.com/users/brendon/followers","following_url":"https://api.github.com/users/brendon/following{/other_user}","gists_url":"https://api.github.com/users/brendon/gists{/gist_id}","starred_url":"https://api.github.com/users/brendon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendon/subscriptions","organizations_url":"https://api.github.com/users/brendon/orgs","repos_url":"https://api.github.com/users/brendon/repos","events_url":"https://api.github.com/users/brendon/events{/privacy}","received_events_url":"https://api.github.com/users/brendon/received_events","type":"User","site_admin":false},"labels":[{"id":40910635,"url":"https://api.github.com/repos/thoughtbot/paperclip/labels/Convert%20to%20PR","name":"Convert to PR","color":"fad8c7","default":false},{"id":340175196,"url":"https://api.github.com/repos/thoughtbot/paperclip/labels/help%20wanted","name":"help wanted","color":"fef2c0","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2015-02-20T03:16:52Z","updated_at":"2018-04-27T20:29:33Z","closed_at":"2018-04-27T20:29:32Z","author_association":"NONE","body":"I use this code to re-assign attachments to `dup`'d records:\n\n``` ruby\nmodule Paperclip\n  class HasAttachedFile\n    def define_with_extensions\n      define_without_extensions\n      define_clone_override\n    end\n\n    alias_method_chain :define, :extensions\n\n    private\n\n    def define_clone_override\n      name = @name\n      @klass.send :define_method, \"dup\" do\n        copy = super()\n        self.class.attachment_definitions.each do |name, options|\n          copy.send \"#{name}=\", send(name)\n        end\n\n        copy\n      end\n    end\n  end\nend\n```\n\nIt works well unless the record being `dup`'d is dirty. It doesn't have to be a change to the attachment, simply a change to any column will cause the issue.\n\nThe issue is that the file doesn't get assigned to the `dup`'d record. Looking at the logs, paperclip does indeed process the file, but it's never saved. I'm guessing maybe it overwrites the existing file from the original record instead. Following the processing in the logs there is also paperclip deleting the files assigned to the original record. The files still exist though, but this is probably just because the new file is the same name as the old file.\n\nCould this be related to caching the file path?\n"}}
{"actor":{"display_login":"mike-burns"}}