From 120ee02f0ccd8c131fb7970caf8ad322954c707c Mon Sep 17 00:00:00 2001 From: manson Date: Tue, 15 Jul 2014 15:34:51 +0800 Subject: [PATCH] Fix url encode and rescue in duration --- app/controllers/admin/diplomas_controller.rb | 6 +++--- app/models/diploma.rb | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/diplomas_controller.rb b/app/controllers/admin/diplomas_controller.rb index f9e1e23..ce6d9fa 100644 --- a/app/controllers/admin/diplomas_controller.rb +++ b/app/controllers/admin/diplomas_controller.rb @@ -17,7 +17,7 @@ class Admin::DiplomasController < OrbitMemberController @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil @diploma = Diploma.new(diploma_params) @diploma.save - redirect_to '/admin/members/'+@member.to_param+'/Diploma' + redirect_to URI.encode('/admin/members/'+@member.to_param+'/Diploma') end def edit @@ -30,7 +30,7 @@ class Admin::DiplomasController < OrbitMemberController @diploma = Diploma.find(params[:id]) @diploma.update_attributes(diploma_params) @diploma.save - redirect_to '/admin/members/'+@member.to_param+'/Diploma' + redirect_to URI.encode('/admin/members/'+@member.to_param+'/Diploma') end def destroy @@ -66,7 +66,7 @@ class Admin::DiplomasController < OrbitMemberController @intro = @intro.nil? ? DiplomaIntro.new({:member_profile_id=>@member.id}) : @intro @intro.update_attributes(intro_params) @intro.save - redirect_to '/admin/members/'+@member.to_param+'/Diploma' + redirect_to URI.encode('/admin/members/'+@member.to_param+'/Diploma') end def get_settings diff --git a/app/models/diploma.rb b/app/models/diploma.rb index c97fe47..82b7d2e 100644 --- a/app/models/diploma.rb +++ b/app/models/diploma.rb @@ -26,7 +26,11 @@ class Diploma before_validation :add_http def duration - self.start_date.strftime('%Y.%m')+' ~ '+self.end_date.strftime('%Y.%m') + if !self.start_date.nil? or !self.end_date.nil? + (self.start_date.strftime('%Y.%m') rescue "")+' ~ '+(self.end_date.strftime('%Y.%m') rescue "") + else + "" + end end def slug_title