如果没有上传图片就会报空指针

This commit is contained in:
lizanle 2015-03-20 11:08:27 +08:00
parent 0424fc55db
commit a4567396e4
1 changed files with 6 additions and 4 deletions

View File

@ -26,10 +26,12 @@ class DiscussDemosController < ApplicationController
def destroy
asset = Kindeditor::Asset.find_by_owner_id(params[:id])
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
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
DiscussDemo.destroy(params[:id])
redirect_to :controller=> 'discuss_demos',:action => 'index'
end