From 6a45a0287d46a20f025a8e9255f36d6000357d83 Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 15 Jul 2014 16:13:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99=E7=95=8C=E9=9D=A2?= =?UTF-8?q?form.quene=20undefine=E7=9A=84js=E9=94=99=E8=AF=AF=EF=BC=88?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=8A=A0=E8=BD=BD=E4=B8=AD=E4=B8=8D=E6=B6=88?= =?UTF-8?q?=E5=A4=B1=E7=9A=84=E5=8E=9F=E5=9B=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/avatar_controller.rb | 36 +++++++++- app/helpers/avatar_helper.rb | 2 +- app/views/admin/contest_page_made.html.erb | 2 +- app/views/admin/course_page_made.html.erb | 2 +- app/views/admin/first_page_made.html.erb | 2 +- app/views/avatar/_avatar_form.html.erb | 5 +- app/views/avatar/delete_image.js.erb | 5 ++ app/views/my/account.html.erb | 21 +++--- config/locales/zh.yml | 1 + config/routes.rb | 1 + db/migrate/20140714081030_set_web_title.rb | 1 + db/schema.rb | 76 ++++++++++++++++++---- public/javascripts/application.js | 2 +- public/javascripts/avatars.js | 1 + 14 files changed, 128 insertions(+), 29 deletions(-) create mode 100644 app/views/avatar/delete_image.js.erb 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 @@ +