fix for honor without name

This commit is contained in:
Harry Bomrah 2014-10-02 19:46:12 +08:00
parent 52b22f3f45
commit 7e23454c93
2 changed files with 18 additions and 8 deletions

View File

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

View File

@ -5,12 +5,12 @@
<%= link_to honor.award_name, OrbitHelper.url_to_plugin_show(honor.to_param,'personal_honor'), target: "blank"%> <%= link_to honor.award_name, OrbitHelper.url_to_plugin_show(honor.to_param,'personal_honor'), target: "blank"%>
<div class="quick-edit"> <div class="quick-edit">
<ul class="nav nav-pills hide"> <ul class="nav nav-pills hide">
<li><%= link_to t('edit'), '/admin/members/'+honor.member_profile.to_param+'/honors/'+honor.id+'/edit' %></li> <li><%= link_to t('edit'), edit_admin_honor_path(honor) %></li>
<li><%= link_to t(:delete_), admin_honor_path(id: honor.id, member_profile_id: honor.member_profile.id), method: :delete, remote: true, data: { confirm: t('sure?') } %></li> <li><%= link_to t(:delete_), admin_honor_path(id: honor.id), method: :delete, remote: true, data: { confirm: 'Are you sure?' } %></li>
</ul> </ul>
</div> </div>
</td> </td>
<td><%= honor.awarding_unit %></td> <td><%= honor.awarding_unit %></td>
<td><%= honor.member_profile.name %></td> <td><%= honor.member_profile.name rescue "" %></td>
</tr> </tr>
<% end %> <% end %>