diff --git a/app/controllers/admin/honors_controller.rb b/app/controllers/admin/honors_controller.rb index 798c90d..3139752 100644 --- a/app/controllers/admin/honors_controller.rb +++ b/app/controllers/admin/honors_controller.rb @@ -1,6 +1,7 @@ class Admin::HonorsController < OrbitMemberController layout "member_plugin" + before_action :set_honor, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -24,20 +25,17 @@ class Admin::HonorsController < OrbitMemberController end def edit - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @honor = Honor.find(params[:id]) + @member = @honor.member_profile rescue nil end def update - @member = MemberProfile.find(honor_params['member_profile_id']) rescue nil - @honor = Honor.find(params[:id]) + @member = @honor.member_profile rescue nil @honor.update_attributes(honor_params) @honor.save redirect_to params['referer_url'] end def destroy - @honor = Honor.find(params[:id]) @honor.destroy end @@ -82,6 +80,18 @@ class Admin::HonorsController < OrbitMemberController private + def set_honor + 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 + @honor = Honor.find_by(:uid => uid) rescue Honor.find(params[:id]) + end + def honor_params params.require(:honor).permit! rescue nil end diff --git a/app/views/admin/honors/_honor.html.erb b/app/views/admin/honors/_honor.html.erb index ee6629b..1b4949f 100644 --- a/app/views/admin/honors/_honor.html.erb +++ b/app/views/admin/honors/_honor.html.erb @@ -5,12 +5,12 @@ <%= link_to honor.award_name, OrbitHelper.url_to_plugin_show(honor.to_param,'personal_honor'), target: "blank"%>