From 1289ad9f9de3d88d83f539b9b034b20b5103e3e9 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 5 Dec 2012 14:51:12 +0800 Subject: [PATCH] fixed co-author relation bug.... --- .../desktop/co_author_relations_controller.rb | 11 ++++++++++- app/helpers/desktop/co_author_relations_helper.rb | 6 ------ .../desktop/co_author_relations/_show_form.html.erb | 6 ++---- app/views/desktop/co_author_relations/index.html.erb | 4 +++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/desktop/co_author_relations_controller.rb b/app/controllers/desktop/co_author_relations_controller.rb index edeeacb8..787ad36c 100644 --- a/app/controllers/desktop/co_author_relations_controller.rb +++ b/app/controllers/desktop/co_author_relations_controller.rb @@ -27,8 +27,17 @@ class Desktop::CoAuthorRelationsController < ApplicationController def destroy @co_author_relation = CoAuthorRelation.find(params[:id]) @co_author_relation.destroy - #reset_co_author_relation @co_author_relation + reset_co_author_relation render :json => {success: true, msg: "deleted successfully!"} end + + private + + def reset_co_author_relation + co_author = CoAuthor.where(co_author_relations_id: @co_author_relation.id) + co_author.map do |c| + c.update_attributes(co_author_relations_id: nil) + end + end end diff --git a/app/helpers/desktop/co_author_relations_helper.rb b/app/helpers/desktop/co_author_relations_helper.rb index 7de13211..fa03bbae 100644 --- a/app/helpers/desktop/co_author_relations_helper.rb +++ b/app/helpers/desktop/co_author_relations_helper.rb @@ -1,8 +1,2 @@ module Desktop::CoAuthorRelationsHelper - def reset_co_author_relation relation - co_author = CoAuthor.where(co_author_relations_id: relation) - co_author.map do |c| - co_author.update_attributes(co_author_relations_id: nil) - end - end end diff --git a/app/views/desktop/co_author_relations/_show_form.html.erb b/app/views/desktop/co_author_relations/_show_form.html.erb index 28ded992..bdb9f72e 100644 --- a/app/views/desktop/co_author_relations/_show_form.html.erb +++ b/app/views/desktop/co_author_relations/_show_form.html.erb @@ -1,6 +1,4 @@ -<%# @co_author_relations.each do |co_author_relation| %> - <%= show_form.relation %> - <%= link_to 'Destroy', desktop_co_author_relation_path(show_form), confirm: 'Are you sure?', method: :delete, :class=>"bt-delete" %> + <%= co_author_relation.relation %> + <%= link_to 'Destroy', desktop_co_author_relation_path(co_author_relation), confirm: 'Are you sure?', method: :delete, :class=>"bt-delete" %> -<%# end %> diff --git a/app/views/desktop/co_author_relations/index.html.erb b/app/views/desktop/co_author_relations/index.html.erb index 0b91d143..24791349 100644 --- a/app/views/desktop/co_author_relations/index.html.erb +++ b/app/views/desktop/co_author_relations/index.html.erb @@ -12,6 +12,8 @@ - <%= render :partial => 'show_form', :collection => @co_author_relations %> + <% @co_author_relations.each do |co_author_relation| %> + <%= render :partial => 'show_form', locals: {:co_author_relation => co_author_relation} %> + <% end %>