diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index 73c1dbd90..fa7eb6052 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -2,7 +2,7 @@ class AvatarController < ApplicationController #before_filter :set_cache_buster - include AvatarHelper + include AvatarHelper def upload # Make sure that API users get used to set this content type @@ -77,6 +77,40 @@ class AvatarController < ApplicationController } end end + + #add by zjc + #删除图片 + def delete_image + @source_type = params[:source_type] + @source_id = params[:source_id] + @source = nil #eval(@source_type).find(@source_id) + c = Object.const_get(@source_type) + if c.respond_to?(:find) + @source = c.find(@source_id) + end + + diskfile=disk_filename(@source_type,@source_id) + unless diskfile.nil? || diskfile == "" + path = File.dirname(diskfile) + if File.directory?(path) && File.exist?(diskfile) + File.delete(diskfile) + end + end + rescue e do + logger.info e.message + end + respond_to do |format| + format.js + format.api { + if saved + render :action => 'upload', :status => :created + else + render_validation_errors(@avatar) + end + } + end + + end private diff --git a/app/helpers/avatar_helper.rb b/app/helpers/avatar_helper.rb index 2ebdae0c8..3f6802f59 100644 --- a/app/helpers/avatar_helper.rb +++ b/app/helpers/avatar_helper.rb @@ -38,7 +38,7 @@ module AvatarHelper avatar_image(source) else File.join(relative_path,avatar_directory(source.class),'0') - end + end end def get_avatar?(source) diff --git a/app/views/admin/contest_page_made.html.erb b/app/views/admin/contest_page_made.html.erb index b8a86fa4d..a4407cd6b 100644 --- a/app/views/admin/contest_page_made.html.erb +++ b/app/views/admin/contest_page_made.html.erb @@ -17,7 +17,7 @@

-
+
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@contest_page} %>

diff --git a/app/views/admin/course_page_made.html.erb b/app/views/admin/course_page_made.html.erb index 4554fb8e0..7d73c7c6e 100644 --- a/app/views/admin/course_page_made.html.erb +++ b/app/views/admin/course_page_made.html.erb @@ -16,7 +16,7 @@

-
+
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@course_page} %>

diff --git a/app/views/admin/first_page_made.html.erb b/app/views/admin/first_page_made.html.erb index a64bbb443..d3b7416e4 100644 --- a/app/views/admin/first_page_made.html.erb +++ b/app/views/admin/first_page_made.html.erb @@ -16,7 +16,7 @@

-
+
<%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source:@first_page} %>
diff --git a/app/views/avatar/_avatar_form.html.erb b/app/views/avatar/_avatar_form.html.erb index a880f32aa..6f9b9c7b1 100644 --- a/app/views/avatar/_avatar_form.html.erb +++ b/app/views/avatar/_avatar_form.html.erb @@ -1,3 +1,4 @@ +