Module | AttachmentHelper |
In: |
app/helpers/attachment_helper.rb
|
添付ファイルを削除するための check box を返す。
# File app/helpers/attachment_helper.rb, line 8 8: def check_box_to_delete(attachment) 9: if attachment.new_record? 10: file_id = attachment.file_id 11: name = attachment.file_type.underscore 12: check_box_tag("#{name}[]", file_id, false, :id => "#{name}_#{file_id}") 13: else 14: check_box_tag("attachment[]", attachment.id, false, :id => "attachment_#{attachment.id}") 15: end 16: end
添付対象の情報を埋め込むためのタグを返す。
# File app/helpers/attachment_helper.rb, line 3 3: def hidden_attachable(name, x) 4: hidden_field_tag name, @attachment.attributes["attachable_#{name}"], {:id => "attachable_#{name}_#{x}"} 5: end
添付ファイルのサマリを返す。
# File app/helpers/attachment_helper.rb, line 35 35: def summary 36: result = [] 37: if (count = @attachments.size) > 0 38: result << ns_("Attachment|%{count} file attached", "%{count} files attached", count) % {:count => count} 39: else 40: result << s_("Attachment|no file attached") 41: end 42: if session[:uploaded_attachments] 43: if @attachable 44: uploaded_attachments = session[:uploaded_attachments].select {|a| a.attachable == @attachable} 45: else 46: uploaded_attachments = session[:uploaded_attachments].select {|a| a.attachable_type == params[:type] && !a.attachable_id} 47: end 48: if (count = uploaded_attachments.size) > 0 49: result << ns_("Attachment|%{count} file uploaded", "%{count} files uploaded", count) % {:count => count} 50: end 51: end 52: if @attachable 53: if session[:deleted_attachments] && (count = session[:deleted_attachments].select {|a| a.attachable == @attachable}.size) > 0 54: result << ns_("Attachment|%{count} file will be deleted", "%{count} files will be deleted", count) % {:count => count} 55: end 56: end 57: s_("Attachment|Attachments: ") + result.join(" / ") 58: end
添付ファイルの更新日時を返す。
# File app/helpers/attachment_helper.rb, line 30 30: def updated_at(attachment) 31: (t = (attachment.updated_at || attachment.created_at || attachment.file.updated_at || attachment.file.created_at)) ? t.strftime("%Y/%m/%d %H:%M:%S") : "" 32: end
添付ファイルをダウンロードするための URL を返す。
# File app/helpers/attachment_helper.rb, line 19 19: def url_to_download(attachment) 20: if attachment.file_type == "StorageObject" 21: attachment.file.uri 22: elsif attachment.new_record? 23: url_for(:controller => attachment.file_type.underscore, :action => "download", :id => attachment.file_id) 24: else 25: url_for(:action => "download", :id => attachment.id) 26: end 27: end