Browse Source

Refactor out not found methods

pull/114/head
baarkerlounger 4 years ago
parent
commit
989a387956
  1. 7
      app/controllers/application_controller.rb
  2. 14
      app/controllers/case_logs_controller.rb

7
app/controllers/application_controller.rb

@ -1,2 +1,9 @@
class ApplicationController < ActionController::Base
def render_not_found_html
render file: "#{Rails.root}/public/404.html", status: 404
end
def render_not_found_json(class_name, id)
render json: { error: "#{class_name} #{id} not found" }, status: :not_found
end
end

14
app/controllers/case_logs_controller.rb

@ -30,7 +30,7 @@ class CaseLogsController < ApplicationController
render json: { errors: case_log.errors.messages }, status: :unprocessable_entity
end
else
render json: { error: "Case Log #{params[:id]} not found" }, status: :not_found
render_not_found_json("Case log", params[:id])
end
end
@ -42,7 +42,7 @@ class CaseLogsController < ApplicationController
if (case_log = CaseLog.find_by(id: params[:id]))
render json: case_log, status: :ok
else
render json: { error: "Case Log #{params[:id]} not found" }, status: :not_found
render_not_found_json("Case log", params[:id])
end
end
end
@ -54,7 +54,7 @@ class CaseLogsController < ApplicationController
if @case_log
render :edit
else
render file: "#{Rails.root}/public/404.html", status: 404
render_not_found_html
end
end
@ -72,7 +72,7 @@ class CaseLogsController < ApplicationController
render "form/page", locals: { form: form, page: page, subsection: subsection.label }, status: :unprocessable_entity
end
else
render file: "#{Rails.root}/public/404.html", status: 404
render_not_found_html
end
end
@ -84,7 +84,7 @@ class CaseLogsController < ApplicationController
render json: { errors: case_log.errors.messages }, status: :unprocessable_entity
end
else
render json: { error: "Case Log #{params[:id]} not found" }, status: :not_found
render_not_found_json("Case log", params[:id])
end
end
@ -96,7 +96,7 @@ class CaseLogsController < ApplicationController
subsection = form.get_subsection(current_url.split("/")[-2])
render "form/check_answers", locals: { subsection: subsection, form: form }
else
render file: "#{Rails.root}/public/404.html", status: 404
render_not_found_html
end
end
@ -108,7 +108,7 @@ class CaseLogsController < ApplicationController
subsection = form.subsection_for_page(page)
render "form/page", locals: { form: form, page: page, subsection: subsection.label }
else
render file: "#{Rails.root}/public/404.html", status: 404
render_not_found_html
end
end
end

Loading…
Cancel
Save