Commit 9844c1f2 authored by Martin Cabrera's avatar Martin Cabrera

Refactored ‘from’ and ‘to’ variable preservation

parent 87c39b6d
...@@ -27,8 +27,11 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -27,8 +27,11 @@ class Projects::CompareController < Projects::ApplicationController
def create def create
if params[:from].blank? || params[:to].blank? if params[:from].blank? || params[:to].blank?
flash[:alert] = "You must select from and to branches" flash[:alert] = "You must select from and to branches"
from_to_preservation = from_to_hash(params) from_to_vars = {
redirect_to namespace_project_compare_index_path(@project.namespace, @project, from_to_preservation) from: params[:from].presence,
to: params[:to].presence
}
redirect_to namespace_project_compare_index_path(@project.namespace, @project, from_to_vars)
else else
redirect_to namespace_project_compare_path(@project.namespace, @project, redirect_to namespace_project_compare_path(@project.namespace, @project,
params[:from], params[:to]) params[:from], params[:to])
...@@ -62,11 +65,4 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -62,11 +65,4 @@ class Projects::CompareController < Projects::ApplicationController
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened. @merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened.
find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref) find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
end end
end
def from_to_hash(params) \ No newline at end of file
return_hash = {}
return_hash[:from] = params[:from].presence
return_hash[:to] = params[:to].presence
return_hash
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