Last active
August 29, 2015 14:17
-
-
Save pete-a/985048d97a36718efd9e to your computer and use it in GitHub Desktop.
Nested if refactor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/mogeneration/adomatic/blob/ruth/feature/duplicate_job/app/controllers/jobs_controller.rb#L32 | |
if check_required_fields @job | |
if @job.save | |
@job.send_status_email | |
if current_user.is_admin? | |
redirect_to admin_organisation_job_queue_job_url(@job.job_queue.organisation, @job.job_queue, @job), notice: 'Job was successfully created.' | |
else | |
redirect_to job_queue_job_url(@job.job_queue, @job), notice: 'Job was successfully created.' | |
end | |
else | |
render action: 'duplicate_job' | |
end | |
else | |
render action: 'duplicate_job' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if check_required_fields(@job) && @job.save | |
@job.send_status_email | |
if current_user.is_admin? | |
redirect_to admin_organisation_job_queue_job_url(@job.job_queue.organisation, @job.job_queue, @job), notice: 'Job was successfully created.' | |
else | |
redirect_to job_queue_job_url(@job.job_queue, @job), notice: 'Job was successfully created.' | |
end | |
else | |
render action: 'duplicate_job' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if check_required_fields(@job) && @job.save | |
@job.send_status_email | |
redirect_to_job(@job) | |
else | |
render action: 'duplicate_job' | |
end | |
#.... | |
private | |
def redirect_to_job(job) | |
if current_user.is_admin? | |
redirect_to admin_organisation_job_queue_job_url(job.job_queue.organisation, job.job_queue, @job), notice: 'Job was successfully created.' | |
else | |
redirect_to job_queue_job_url(job.job_queue, job), notice: 'Job was successfully created.' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment