From e049ca73cf0b1a15bdf054667430f3a19a50bce4 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 2 Oct 2014 20:00:04 +0800 Subject: [PATCH] fix for research without name --- app/controllers/admin/researchs_controller.rb | 20 ++++++++++++++----- app/views/admin/researchs/_research.html.erb | 6 +++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/researchs_controller.rb b/app/controllers/admin/researchs_controller.rb index 843d046..acb6856 100644 --- a/app/controllers/admin/researchs_controller.rb +++ b/app/controllers/admin/researchs_controller.rb @@ -1,6 +1,7 @@ class Admin::ResearchsController < OrbitMemberController layout "member_plugin" + before_action :set_research, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -24,20 +25,17 @@ class Admin::ResearchsController < OrbitMemberController end def edit - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @research = Research.find(params[:id]) + @member = @research.member_profile rescue nil end def update - @member = MemberProfile.find(research_params['member_profile_id']) rescue nil - @research = Research.find(params[:id]) + @member = @research.member_profile rescue nil @research.update_attributes(research_params) @research.save redirect_to params['referer_url'] end def destroy - @research = Research.find(params[:id]) @research.destroy end @@ -81,6 +79,18 @@ class Admin::ResearchsController < OrbitMemberController private + def set_research + 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 + @research = Research.find_by(:uid => uid) rescue Research.find(params[:id]) + end + def research_params params.require(:research).permit! rescue nil end diff --git a/app/views/admin/researchs/_research.html.erb b/app/views/admin/researchs/_research.html.erb index 315161a..4d3af23 100644 --- a/app/views/admin/researchs/_research.html.erb +++ b/app/views/admin/researchs/_research.html.erb @@ -6,11 +6,11 @@ <%= link_to research.research_title, OrbitHelper.url_to_plugin_show(research.to_param,'personal_research'), target: "blank"%>
- <%= research.member_profile.name %> + <%= research.member_profile.name rescue "" %> <% end %> \ No newline at end of file