Patch #1023 ยป attachment_thumbs.diff
| app/controllers/attachments_controller.rb (working copy) | ||
|---|---|---|
|
def download
|
||
|
# images are sent inline
|
||
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||
|
send_file params[:thumb] ? @attachment.thumbfile : @attachment.diskfile,
|
||
|
:filename => filename_for_content_disposition(@attachment.filename),
|
||
|
:type => @attachment.content_type,
|
||
|
:disposition => (@attachment.image? ? 'inline' : 'attachment')
|
||
|
rescue
|
||
|
# in case the disk file was deleted
|
||
|
render_404
|
||
|
end
|
||
|
|
||
|
private
|
||
|
def find_project
|
||
|
@attachment = Attachment.find(params[:id])
|
||
| app/views/attachments/_links.rhtml (working copy) | ||
|---|---|---|
|
<div class="attachments">
|
||
|
<% for attachment in attachments %>
|
||
|
<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' -%>
|
||
|
<% attachments.each do |attachment| -%>
|
||
|
<% if attachment.image? and File.exist?(attachment.thumbfile) -%>
|
||
|
<p><%= link_to image_tag(url_for(:controller => :attachments,:action => :download,:thumb => 1,:id => attachment))+' '+attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment } -%>
|
||
|
<% else -%>
|
||
|
<p><%= link_to attachment.filename, {:controller => 'attachments', :action => 'download', :id => attachment }, :class => 'icon icon-attachment' %>
|
||
|
<% end -%>
|
||
|
<%= h(" - #{attachment.description}") unless attachment.description.blank? %>
|
||
|
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
|
||
|
<% if options[:delete_url] %>
|
||
| app/models/attachment.rb (working copy) | ||
|---|---|---|
|
nil
|
||
|
end
|
||
|
def make_thumbnail
|
||
|
img = Magick::Image.read(diskfile).first
|
||
|
thumb = img.thumbnail(75,75)
|
||
|
thumb.write thumbfile
|
||
|
end
|
||
|
def thumbfile
|
||
|
"#{File.dirname(diskfile)}/thumb_#{File.basename(diskfile)}"
|
||
|
end
|
||
|
# Copy temp file to its final location
|
||
|
def before_save
|
||
|
if @temp_file && (@temp_file.size > 0)
|
||
| ... | ... | |
|
f.write(@temp_file.read)
|
||
|
end
|
||
|
self.digest = Digest::MD5.hexdigest(File.read(diskfile))
|
||
|
make_thumbnail if image? and Object.const_defined?(:Magick)
|
||
|
end
|
||
|
# Don't save the content type if it's longer than the authorized length
|
||
|
if self.content_type && self.content_type.length > 255
|
||