From 75e75ec5c70ec3dc7277cd685927682bc212968c Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 2 Oct 2014 19:20:34 +0800 Subject: [PATCH] fixed bug for diplomas without member_profile --- app/controllers/admin/diplomas_controller.rb | 20 +++++++++++++++----- app/views/admin/diplomas/_diploma.html.erb | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/diplomas_controller.rb b/app/controllers/admin/diplomas_controller.rb index ea9bf7e..9d7378f 100644 --- a/app/controllers/admin/diplomas_controller.rb +++ b/app/controllers/admin/diplomas_controller.rb @@ -1,6 +1,7 @@ class Admin::DiplomasController < OrbitMemberController layout "member_plugin" + before_action :set_diploma, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -24,20 +25,17 @@ class Admin::DiplomasController < OrbitMemberController end def edit - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @diploma = Diploma.find(params[:id]) + @member = @diploma.member_profile rescue nil end def update - @member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil - @diploma = Diploma.find(params[:id]) + @member = @diploma.member_profile rescue nil @diploma.update_attributes(diploma_params) @diploma.save redirect_to params['referer_url'] end def destroy - @diploma = Diploma.find(params[:id]) @diploma.destroy end @@ -84,6 +82,18 @@ class Admin::DiplomasController < OrbitMemberController private + def set_diploma + path = request.path.split('/') + if path.last.include? '-' + uid = path[-1].split("-").last + uid = uid.split("?").first + else + uid = path[-2].split("-").last + uid = uid.split("?").first + end + @diploma = Diploma.find_by(:uid => uid) rescue Diploma.find(params[:id]) + end + def diploma_params params.require(:diploma).permit! rescue nil end diff --git a/app/views/admin/diplomas/_diploma.html.erb b/app/views/admin/diplomas/_diploma.html.erb index 14c6019..b63046b 100644 --- a/app/views/admin/diplomas/_diploma.html.erb +++ b/app/views/admin/diplomas/_diploma.html.erb @@ -6,8 +6,8 @@ <%= link_to diploma.school_name, OrbitHelper.url_to_plugin_show(diploma.to_param,'personal_diploma'), target: "blank"%>