From 3ee52f175e743d21281f993009441101479db5e0 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 2 Oct 2014 19:54:54 +0800 Subject: [PATCH] fix for experience without name --- .../admin/experiences_controller.rb | 20 ++++++++++++++----- .../admin/experiences/_experience.html.erb | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/experiences_controller.rb b/app/controllers/admin/experiences_controller.rb index ca0c711..b98a3dc 100644 --- a/app/controllers/admin/experiences_controller.rb +++ b/app/controllers/admin/experiences_controller.rb @@ -1,6 +1,7 @@ class Admin::ExperiencesController < OrbitMemberController layout "member_plugin" + before_action :set_experience, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -24,20 +25,17 @@ class Admin::ExperiencesController < OrbitMemberController end def edit - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @experience = Experience.find(params[:id]) + @member = @experience.member_profile rescue nil end def update - @member = MemberProfile.find(experience_params['member_profile_id']) rescue nil - @experience = Experience.find(params[:id]) + @member = @experience.member_profile rescue nil @experience.update_attributes(experience_params) @experience.save redirect_to params['referer_url'] end def destroy - @experience = Experience.find(params[:id]) @experience.destroy end @@ -82,6 +80,18 @@ class Admin::ExperiencesController < OrbitMemberController private + def set_experience + 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 + @experience = Experience.find_by(:uid => uid) rescue Experience.find("53c4fd3548345219f04c0000") + end + def experience_params params.require(:experience).permit! rescue nil end diff --git a/app/views/admin/experiences/_experience.html.erb b/app/views/admin/experiences/_experience.html.erb index 43aaa0a..5059c1b 100644 --- a/app/views/admin/experiences/_experience.html.erb +++ b/app/views/admin/experiences/_experience.html.erb @@ -5,8 +5,8 @@ <%= link_to experience.organizationt_title, OrbitHelper.url_to_plugin_show(experience.to_param,'personal_experience'), target: "blank"%>