Commit e5a365e5c9bbf9ec596f6aa7afb2389d2108bf34
1 parent
9391cbdb
Exists in
colab
and in
4 other branches
RepositoriesController#create refactored to reduce it's complexity
Showing
2 changed files
with
13 additions
and
8 deletions
Show diff stats
app/controllers/projects_controller.rb
@@ -21,7 +21,7 @@ class ProjectsController < ApplicationController | @@ -21,7 +21,7 @@ class ProjectsController < ApplicationController | ||
21 | def create | 21 | def create |
22 | @project = Project.new(project_params) | 22 | @project = Project.new(project_params) |
23 | respond_to do |format| | 23 | respond_to do |format| |
24 | - create_project_and_redir(format) | 24 | + create_and_redir(format) |
25 | end | 25 | end |
26 | end | 26 | end |
27 | 27 | ||
@@ -71,7 +71,7 @@ class ProjectsController < ApplicationController | @@ -71,7 +71,7 @@ class ProjectsController < ApplicationController | ||
71 | end | 71 | end |
72 | 72 | ||
73 | # Extracted code from create action | 73 | # Extracted code from create action |
74 | - def create_project_and_redir(format) | 74 | + def create_and_redir(format) |
75 | if @project.save | 75 | if @project.save |
76 | current_user.project_ownerships.create project_id: @project.id | 76 | current_user.project_ownerships.create project_id: @project.id |
77 | 77 |
app/controllers/repositories_controller.rb
@@ -36,12 +36,7 @@ class RepositoriesController < ApplicationController | @@ -36,12 +36,7 @@ class RepositoriesController < ApplicationController | ||
36 | @repository.project_id = params[:project_id] | 36 | @repository.project_id = params[:project_id] |
37 | 37 | ||
38 | respond_to do |format| | 38 | respond_to do |format| |
39 | - if @repository.save | ||
40 | - format.html { redirect_to project_path(params[:project_id]), notice: 'Repository was successfully created.' } | ||
41 | - format.json { render action: 'show', status: :created, location: @repository } | ||
42 | - else | ||
43 | - failed_action(format, 'new') | ||
44 | - end | 39 | + create_and_redir(format) |
45 | end | 40 | end |
46 | end | 41 | end |
47 | 42 | ||
@@ -101,4 +96,14 @@ private | @@ -101,4 +96,14 @@ private | ||
101 | def process_respository | 96 | def process_respository |
102 | @repository.process if @repository.persisted? | 97 | @repository.process if @repository.persisted? |
103 | end | 98 | end |
99 | + | ||
100 | + # Code extracted from create action | ||
101 | + def create_and_redir(format) | ||
102 | + if @repository.save | ||
103 | + format.html { redirect_to project_path(params[:project_id]), notice: 'Repository was successfully created.' } | ||
104 | + format.json { render action: 'show', status: :created, location: @repository } | ||
105 | + else | ||
106 | + failed_action(format, 'new') | ||
107 | + end | ||
108 | + end | ||
104 | end | 109 | end |