fixed bug for diplomas without member_profile

This commit is contained in:
Harry Bomrah 2014-10-02 19:20:34 +08:00
parent 774df67db0
commit 75e75ec5c7
2 changed files with 17 additions and 7 deletions

View File

@ -1,6 +1,7 @@
class Admin::DiplomasController < OrbitMemberController
layout "member_plugin"
before_action :set_diploma, only: [:show, :edit , :update, :destroy]
before_action :set_plugin
before_action :get_settings,:only => [:new, :edit, :setting]
@ -24,20 +25,17 @@ class Admin::DiplomasController < OrbitMemberController
end
def edit
@member = MemberProfile.find_by(:uid=>params['uid']) rescue nil
@diploma = Diploma.find(params[:id])
@member = @diploma.member_profile rescue nil
end
def update
@member = MemberProfile.find(diploma_params['member_profile_id']) rescue nil
@diploma = Diploma.find(params[:id])
@member = @diploma.member_profile rescue nil
@diploma.update_attributes(diploma_params)
@diploma.save
redirect_to params['referer_url']
end
def destroy
@diploma = Diploma.find(params[:id])
@diploma.destroy
end
@ -84,6 +82,18 @@ class Admin::DiplomasController < OrbitMemberController
private
def set_diploma
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
@diploma = Diploma.find_by(:uid => uid) rescue Diploma.find(params[:id])
end
def diploma_params
params.require(:diploma).permit! rescue nil
end

View File

@ -6,8 +6,8 @@
<%= link_to diploma.school_name, OrbitHelper.url_to_plugin_show(diploma.to_param,'personal_diploma'), target: "blank"%>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t('edit'), '/admin/members/'+diploma.member_profile.to_param+'/diplomas/'+diploma.id+'/edit' %></li>
<li><%= link_to t(:delete_), admin_diploma_path(id: diploma.id, member_profile_id: diploma.member_profile.id), method: :delete, remote: true, data: { confirm: t('sure?') } %></li>
<li><%= link_to t('edit'), edit_admin_diploma_path(diploma) %></li>
<li><%= link_to t(:delete_), admin_diploma_path(id: diploma.id), method: :delete, remote: true, data: { confirm: 'Are you sure?' } %></li>
</ul>
</div>
</td>