From 0d487efea8724d2d190e2ee162dfd23ca80594b3 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Thu, 26 Mar 2015 15:43:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=A4=E4=B8=AA=E5=85=AC?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=96=B9=E6=B3=95=E3=80=82=E4=BB=8E=E7=A1=AC?= =?UTF-8?q?=E7=9B=98=E4=B8=8A=E5=88=A0=E9=99=A4=E5=AF=B9=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6=E7=9A=84owner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b4f54f075..a5cfc2b16 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,35 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + # Time 2015-03-24 15:27:29 + # Author lizanle + # Description 从硬盘上删除对应的资源文件 + def delete_kindeditor_assets_from_disk owner_id,owner_type + assets = Kindeditor::Asset.where(["owner_id = ? and owner_type = ?",owner_id,owner_type]) + if !assets.nil? && !assets.blank? + assets.all.each do |asset| + next if asset.nil? + filepath = File.join(Rails.root,"public","files","uploads", + asset[:created_at].to_s.gsub("+0800","").to_datetime.strftime("%Y%m").to_s, + asset[:asset].to_s) + File.delete(filepath) if File.exist?filepath + end + end + end + + # Time 2015-03-24 16:38:05 + # Author lizanle + # Description after save后需要进行资源记录的更新 + # owner_type = 1 对应的是 memo + def update_kindeditor_assets_owner ids,owner_id,owner_type + ids.each do |id| + asset = Kindeditor::Asset.find(id.to_i) + asset.owner_id = owner_id + asset.owner_type = owner_type + asset.save + end + end + # Added by young # Define the course menu's link class # 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表