Method: Paperclip::Attachment#assign
- Defined in:
- lib/paperclip/attachment.rb
#assign(uploaded_file) ⇒ Object
What gets called when you call instance.attachment = File. It clears errors, assigns attributes, and processes the file. It also queues up the previous file for deletion, to be flushed away on #save of its host. In addition to form uploads, you can also assign another Paperclip attachment:
new_user.avatar = old_user.avatar
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/paperclip/attachment.rb', line 99 def assign(uploaded_file) @file = Paperclip.io_adapters.for(uploaded_file, @options[:adapter_options]) ensure_required_accessors! ensure_required_validations! if @file.assignment? clear(*only_process) if @file.nil? nil else assign_attributes post_process_file reset_file_if_original_reprocessed end else nil end end |