From 84a0d966ed867f4a85ffc6a78c10db70008197e4 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 2 Oct 2014 19:47:39 +0800 Subject: [PATCH] fix for lab without name --- app/controllers/admin/labs_controller.rb | 20 +++++++++++++++----- app/views/admin/labs/_lab.html.erb | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/labs_controller.rb b/app/controllers/admin/labs_controller.rb index 3570edf..7f209bc 100644 --- a/app/controllers/admin/labs_controller.rb +++ b/app/controllers/admin/labs_controller.rb @@ -1,6 +1,7 @@ class Admin::LabsController < OrbitMemberController layout "member_plugin" + before_action :set_lab, only: [:show, :edit , :update, :destroy] before_action :set_plugin before_action :get_settings,:only => [:new, :edit, :setting] @@ -24,20 +25,17 @@ class Admin::LabsController < OrbitMemberController end def edit - @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil - @lab = Lab.find(params[:id]) + @member = @lab.member_profile rescue nil end def update - @member = MemberProfile.find(lab_params['member_profile_id']) rescue nil - @lab = Lab.find(params[:id]) + @member = @lab.member_profile rescue nil @lab.update_attributes(lab_params) @lab.save redirect_to params['referer_url'] end def destroy - @lab = Lab.find(params[:id]) @lab.destroy end @@ -81,6 +79,18 @@ class Admin::LabsController < OrbitMemberController private + def set_lab + 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 + @lab = Lab.find_by(:uid => uid) rescue Lab.find(params[:id]) + end + def lab_params params.require(:lab).permit! rescue nil end diff --git a/app/views/admin/labs/_lab.html.erb b/app/views/admin/labs/_lab.html.erb index dc0891d..fcf83f8 100644 --- a/app/views/admin/labs/_lab.html.erb +++ b/app/views/admin/labs/_lab.html.erb @@ -5,8 +5,8 @@ <%= link_to lab.lab_title, OrbitHelper.url_to_plugin_show(lab.to_param,'personal_lab'), target: "blank"%>