From afbacfb9f94756a5ace4d60890221783551c1bf9 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 2 Oct 2014 19:48:50 +0800 Subject: [PATCH] fix for projects without name --- app/controllers/admin/projects_controller.rb | 20 +++++++++++++++----- app/views/admin/projects/_project.html.erb | 6 +++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 725932a..d4acd30 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -1,6 +1,7 @@ class Admin::ProjectsController < OrbitMemberController layout "member_plugin" + before_action :set_project, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -24,20 +25,17 @@ class Admin::ProjectsController < OrbitMemberController end def edit - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @project = Project.find(params[:id]) + @member = @project.member_profile rescue nil end def update - @member = MemberProfile.find(project_params['member_profile_id']) rescue nil - @project = Project.find(params[:id]) + @member = @project.member_profile rescue nil @project.update_attributes(project_params) @project.save redirect_to params['referer_url'] end def destroy - @project = Project.find(params[:id]) @project.destroy end @@ -82,6 +80,18 @@ class Admin::ProjectsController < OrbitMemberController private + def set_project + 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 + @project = Project.find_by(:uid => uid) rescue Project.find(params[:id]) + end + def project_params params.require(:project).permit! rescue nil end diff --git a/app/views/admin/projects/_project.html.erb b/app/views/admin/projects/_project.html.erb index 5b23138..3a0aaf0 100644 --- a/app/views/admin/projects/_project.html.erb +++ b/app/views/admin/projects/_project.html.erb @@ -5,14 +5,14 @@ <%= link_to project.project_title, OrbitHelper.url_to_plugin_show(project.to_param,'personal_project').to_s, target: "blank"%>
<%= project.job_title %> <%= project.participator %> <%= project.unit %> - <%= project.member_profile.name %> + <%= project.member_profile.name rescue "" %> <% end %> \ No newline at end of file