diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-04-01 15:50:17 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-04-05 11:53:39 -0300 |
commit | 5d428030451b1fa2bac89f798c40d2f91ac65bac (patch) | |
tree | bbbcac1c24552c039bef845b2851750271457f3a /app/controllers/groups | |
parent | 1ba9a91c6d3b98e1825e173fe281ba065d35890c (diff) | |
download | gitlab-ce-5d428030451b1fa2bac89f798c40d2f91ac65bac.tar.gz |
Improve code
Diffstat (limited to 'app/controllers/groups')
-rw-r--r-- | app/controllers/groups/milestones_controller.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index 2c05d9e0fe1..21fc329f233 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -21,10 +21,10 @@ class Groups::MilestonesController < Groups::ApplicationController project_ids = params[:milestone][:project_ids].reject(&:blank?) title = milestone_params[:title] - if project_ids.present? - create_milestones(project_ids, title) + if create_milestones(project_ids, title) + redirect_to milestone_path(title) else - render_new_with_error("Select a project(s).") + render_new_with_error(@error) end end @@ -42,14 +42,22 @@ class Groups::MilestonesController < Groups::ApplicationController private def create_milestones(project_ids, title) + unless project_ids.present? + @error = "Please select at least one project." + return false + end + begin - @projects.where(id: project_ids).each do |project| - ActiveRecord::Base.transaction { Milestones::CreateService.new(project, current_user, milestone_params).execute } + ActiveRecord::Base.transaction do + @projects.where(id: project_ids).each do |project| + Milestones::CreateService.new(project, current_user, milestone_params).execute + end end - redirect_to milestone_path(title) + true rescue => e - render_new_with_error("Error creating milestones: #{e.message}") + @error = "Error creating milestone: #{e.message}." + false end end |