diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/issue_relations_controller.rb | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/app/controllers/issue_relations_controller.rb b/app/controllers/issue_relations_controller.rb index 1cceba576..14ee4c948 100644 --- a/app/controllers/issue_relations_controller.rb +++ b/app/controllers/issue_relations_controller.rb @@ -44,22 +44,29 @@ class IssueRelationsController < ApplicationController end def create - @relation = IssueRelation.new - @relation.issue_from = @issue - @relation.safe_attributes = params[:relation] - @relation.init_journals(User.current) + saved = false + params_relation = params[:relation] + unsaved_relations = [] + + relation_issues_to_id.each do |issue_to_id| + params_relation[:issue_to_id] = issue_to_id + + @relation = IssueRelation.new + @relation.issue_from = @issue + @relation.safe_attributes = params_relation + @relation.init_journals(User.current) - begin - saved = @relation.save - rescue ActiveRecord::RecordNotUnique - saved = false - @relation.errors.add :base, :taken + unless saved = @relation.save + saved = false + unsaved_relations << @relation + end end respond_to do |format| format.html {redirect_to issue_path(@issue)} format.js do @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible?} + @unsaved_relations = unsaved_relations end format.api do if saved @@ -98,4 +105,12 @@ class IssueRelationsController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def relation_issues_to_id + params[:relation].require(:issue_to_id).split(',').reject(&:blank?) + rescue ActionController::ParameterMissing => e + # We return a empty array just to loop once and return a validation error + # ToDo: Find a better method to return an error if the param is missing. + [''] + end end |