限制上传文件名、文件描述长度 #1252

This commit is contained in:
sw 2014-09-17 14:14:17 +08:00
parent 98b6be61ba
commit 0ab7bfcda9
2 changed files with 4 additions and 2 deletions

View File

@ -127,7 +127,7 @@ module ApplicationHelper
# * :text - Link text (default to attachment filename) # * :text - Link text (default to attachment filename)
# * :download - Force download (default: false) # * :download - Force download (default: false)
def link_to_attachment(attachment, options={}) def link_to_attachment(attachment, options={})
text = h(truncate(options.delete(:text) || attachment.filename, length: 60, omission: '...')) text = h(truncate(options.delete(:text) || attachment.filename, length: 25, omission: '...'))
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
html_options = options.slice!(:only_path) html_options = options.slice!(:only_path)
url = send(route_method, attachment, attachment.filename, options) url = send(route_method, attachment, attachment.filename, options)

View File

@ -11,7 +11,9 @@
:id => attachment, :id => attachment,
:filename => attachment.filename%> :filename => attachment.filename%>
<% end %> <% end %>
<%= h(" - #{attachment.description}") unless attachment.description.blank? %> <span title="<%= attachment.description%>">
<%= h(truncate(" - #{attachment.description}", length: 20, omission: '...')) unless attachment.description.blank? %>
</span>
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span> <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<% if options[:deletable] %> <% if options[:deletable] %>
<% if attachment.container_type == 'HomeworkAttach' %> <% if attachment.container_type == 'HomeworkAttach' %>