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 | 21 | def create |
22 | 22 | @project = Project.new(project_params) |
23 | 23 | respond_to do |format| |
24 | - create_project_and_redir(format) | |
24 | + create_and_redir(format) | |
25 | 25 | end |
26 | 26 | end |
27 | 27 | |
... | ... | @@ -71,7 +71,7 @@ class ProjectsController < ApplicationController |
71 | 71 | end |
72 | 72 | |
73 | 73 | # Extracted code from create action |
74 | - def create_project_and_redir(format) | |
74 | + def create_and_redir(format) | |
75 | 75 | if @project.save |
76 | 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 | 36 | @repository.project_id = params[:project_id] |
37 | 37 | |
38 | 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 | 40 | end |
46 | 41 | end |
47 | 42 | |
... | ... | @@ -101,4 +96,14 @@ private |
101 | 96 | def process_respository |
102 | 97 | @repository.process if @repository.persisted? |
103 | 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 | 109 | end | ... | ... |