Module: Paperclip::Storage::Database::ControllerClassMethods

Defined in:
lib/paperclip/storage/database.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



186
187
188
# File 'lib/paperclip/storage/database.rb', line 186

def self.included(base)
  base.extend(self)
end

Instance Method Details

#downloads_files_for(model, attachment) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/paperclip/storage/database.rb', line 189

def downloads_files_for(model, attachment)
  define_method("#{attachment.to_s.pluralize}") do
    user_id = params[:id]
    user_id ||= params[:user_id]
    model_record = Object.const_get(model.to_s.camelize.to_sym).find(user_id)
    style = params[:style] ? params[:style] : 'original'
    send_data model_record.send(attachment).file_contents(style),
              :filename => model_record.send("#{attachment}_file_name".to_sym),
              :type => model_record.send("#{attachment}_content_type".to_sym)
  end
end