diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index eaec5a604..8397092b7 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -49,7 +49,11 @@ class LettingsLogsController < LogsController end def edit - @log = current_user.lettings_logs.find_by(id: params[:id]) + @log = if new_log_request? + LettingsLog.new + else + current_user.lettings_logs.find_by(id: params[:id]) + end if @log render "logs/edit", locals: { current_user: } else @@ -84,6 +88,9 @@ class LettingsLogsController < LogsController def csv_confirmation; end private + def new_log_request? + request.path.include?("new") + end def permitted_log_params params.require(:lettings_log).permit(LettingsLog.editable_fields) diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 3982d4a54..91112a4fe 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -15,8 +15,7 @@ private respond_to do |format| format.html do - log.save! - redirect_to post_create_redirect_url(log) + redirect_to new_log_lettings_logs_path end format.json do if log.save diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index 7ab955a2e..4a187dd3a 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -16,8 +16,12 @@ module TasklistHelper "#{log.class.name.underscore}_#{subsection.id}_check_answers_path" else "#{log.class.name.underscore}_#{next_question_page(subsection, log, current_user)}_path" - end - send(path, log) + end + if log.id + send(path, log) + else + "/logs/new/#{next_question_page(subsection, log, current_user)}" + end end def next_question_page(subsection, log, current_user) diff --git a/app/views/logs/edit.html.erb b/app/views/logs/edit.html.erb index 52943e539..ffceca9bc 100644 --- a/app/views/logs/edit.html.erb +++ b/app/views/logs/edit.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, "Log #{@log.id}" %> +<% content_for :title, "Log #{@log.id ? @log.id : "new"}" %> <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { "Logs" => @log.lettings? ? lettings_logs_path : sales_logs_path, content_for(:title) => "", diff --git a/app/views/logs/index.html.erb b/app/views/logs/index.html.erb index 7c75230d4..a6884ef96 100644 --- a/app/views/logs/index.html.erb +++ b/app/views/logs/index.html.erb @@ -8,7 +8,7 @@
<% if current_page?(:controller => 'lettings_logs', :action => 'index') %> - <%= govuk_button_to "Create a new lettings log", lettings_logs_path %> + <%= govuk_button_to "Create a new lettings log", create_new_log_lettings_logs_path, method: :get %> <% end %> <% if FeatureToggle.sales_log_enabled? && current_page?(:controller => 'sales_logs', :action => 'index') %> <%= govuk_button_to "Create a new sales log", sales_logs_path %> diff --git a/config/routes.rb b/config/routes.rb index 0c4409713..5ec1d7f9c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,6 +80,8 @@ Rails.application.routes.draw do resources :lettings_logs, path: "/lettings-logs" do collection do + get "create-new-log", to: "lettings_logs#create" + get "new-log", to: "lettings_logs#show" post "bulk-upload", to: "bulk_upload#bulk_upload" get "bulk-upload", to: "bulk_upload#show" get "csv-download", to: "lettings_logs#download_csv"