Commit 5d428030 authored by Felipe Artur's avatar Felipe Artur

Improve code

parent 1ba9a91c
...@@ -21,10 +21,10 @@ class Groups::MilestonesController < Groups::ApplicationController ...@@ -21,10 +21,10 @@ class Groups::MilestonesController < Groups::ApplicationController
project_ids = params[:milestone][:project_ids].reject(&:blank?) project_ids = params[:milestone][:project_ids].reject(&:blank?)
title = milestone_params[:title] title = milestone_params[:title]
if project_ids.present? if create_milestones(project_ids, title)
create_milestones(project_ids, title) redirect_to milestone_path(title)
else else
render_new_with_error("Select a project(s).") render_new_with_error(@error)
end end
end end
...@@ -42,14 +42,22 @@ class Groups::MilestonesController < Groups::ApplicationController ...@@ -42,14 +42,22 @@ class Groups::MilestonesController < Groups::ApplicationController
private private
def create_milestones(project_ids, title) def create_milestones(project_ids, title)
unless project_ids.present?
@error = "Please select at least one project."
return false
end
begin begin
ActiveRecord::Base.transaction do
@projects.where(id: project_ids).each do |project| @projects.where(id: project_ids).each do |project|
ActiveRecord::Base.transaction { Milestones::CreateService.new(project, current_user, milestone_params).execute } Milestones::CreateService.new(project, current_user, milestone_params).execute
end
end end
redirect_to milestone_path(title) true
rescue => e rescue => e
render_new_with_error("Error creating milestones: #{e.message}") @error = "Error creating milestone: #{e.message}."
false
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment