Commit 9391cbdbfda28eafd20c891bf34c978dd8ddd222
1 parent
252766fc
Exists in
colab
and in
4 other branches
ProjectsController#create refactored to reduce it's complexity
Showing
1 changed file
with
14 additions
and
9 deletions
Show diff stats
app/controllers/projects_controller.rb
... | ... | @@ -21,15 +21,7 @@ class ProjectsController < ApplicationController |
21 | 21 | def create |
22 | 22 | @project = Project.new(project_params) |
23 | 23 | respond_to do |format| |
24 | - if @project.save | |
25 | - current_user.project_ownerships.create project_id: @project.id | |
26 | - | |
27 | - format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' } | |
28 | - format.json { render action: 'show', status: :created, location: @project } | |
29 | - else | |
30 | - format.html { render action: 'new' } | |
31 | - format.json { render json: @project.errors, status: :unprocessable_entity } | |
32 | - end | |
24 | + create_project_and_redir(format) | |
33 | 25 | end |
34 | 26 | end |
35 | 27 | |
... | ... | @@ -77,4 +69,17 @@ class ProjectsController < ApplicationController |
77 | 69 | def project_params |
78 | 70 | params[:project] |
79 | 71 | end |
72 | + | |
73 | + # Extracted code from create action | |
74 | + def create_project_and_redir(format) | |
75 | + if @project.save | |
76 | + current_user.project_ownerships.create project_id: @project.id | |
77 | + | |
78 | + format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' } | |
79 | + format.json { render action: 'show', status: :created, location: @project } | |
80 | + else | |
81 | + format.html { render action: 'new' } | |
82 | + format.json { render json: @project.errors, status: :unprocessable_entity } | |
83 | + end | |
84 | + end | |
80 | 85 | end | ... | ... |