From acb634b862dfb1344796093a9429b3e8e59ebb66 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 2 Oct 2014 19:58:33 +0800 Subject: [PATCH] fix for patent without name --- app/controllers/admin/patents_controller.rb | 21 ++++++++++++++++----- app/views/admin/patents/_patent.html.erb | 6 +++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/patents_controller.rb b/app/controllers/admin/patents_controller.rb index 41dd067..0c9525a 100644 --- a/app/controllers/admin/patents_controller.rb +++ b/app/controllers/admin/patents_controller.rb @@ -1,6 +1,7 @@ class Admin::PatentsController < OrbitMemberController layout "member_plugin" + before_action :set_patent, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -24,20 +25,17 @@ class Admin::PatentsController < OrbitMemberController end def edit - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @patent = Patent.find(params[:id]) + @member = @patent.member_profile rescue nil end def update - @member = MemberProfile.find(patent_params['member_profile_id']) rescue nil - @patent = Patent.find(params[:id]) + @member = @patent.member_profile rescue nil @patent.update_attributes(patent_params) @patent.save redirect_to params['referer_url'] end def destroy - @patent = Patent.find(params[:id]) @patent.destroy end @@ -82,6 +80,19 @@ class Admin::PatentsController < OrbitMemberController private + def set_patent + 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 + @patent = Patent.find_by(:uid => uid) rescue Patent.find(params[:id]) + end + + def patent_params params.require(:patent).permit! rescue nil end diff --git a/app/views/admin/patents/_patent.html.erb b/app/views/admin/patents/_patent.html.erb index bffef8a..1c3d54b 100644 --- a/app/views/admin/patents/_patent.html.erb +++ b/app/views/admin/patents/_patent.html.erb @@ -5,13 +5,13 @@ <%= link_to patent.patent_title, OrbitHelper.url_to_plugin_show(patent.to_param,'personal_patent').to_s, target: "blank"%>
<%= patent.patent_no %> <%= patent.patent_country %> - <%= patent.member_profile.name %> + <%= patent.member_profile.name rescue "" %> <% end %> \ No newline at end of file