Last active
August 29, 2015 14:13
-
-
Save ksss/ab8a36f8fde27ecaad55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Photo < ActiveRecord::Base | |
| extend Refile::ActiveRecord::Attachment::IDName | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Refile | |
| module ActiveRecord | |
| module Attachment | |
| module IDName | |
| def attachment(name, raise_errors: false, **options) | |
| super | |
| attacher = "#{name}_attacher" | |
| after_save do | |
| store = __send__(attacher).store | |
| case store | |
| when Refile::Backend::FileSystem | |
| ::File.rename store.path(@image_id), store.path(id) | |
| else | |
| fail NotImplementedError | |
| end | |
| end | |
| class_eval "alias #{name}_id id" | |
| define_method :"#{name}_id=" do |value| | |
| instance_variable_set :"@#{name}_id", value | |
| end | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment