From fa06f9d9af9b99feb3202303e631c680a39b115d Mon Sep 17 00:00:00 2001 From: gberzins Date: Fri, 17 May 2024 21:15:24 +0300 Subject: [PATCH 1/7] merge --- app/controllers/application_controller.rb | 1 + app/controllers/spend_forecasts_controller.rb | 21 +++- app/models/spend_forecast.rb | 2 +- app/views/spend_forecasts/_form.html.erb | 116 +++++++++++++++++- app/views/spend_forecasts/new.html.erb | 6 +- config/routes.rb | 2 + 6 files changed, 136 insertions(+), 12 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b5624fb..9e32c6d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,4 +4,5 @@ class ApplicationController < ActionController::Base def current_user @current_user ||= User.first || User.create(channels: %w[facebook radio billboards]) end + helper_method :current_user end diff --git a/app/controllers/spend_forecasts_controller.rb b/app/controllers/spend_forecasts_controller.rb index 409eebf..55db02e 100644 --- a/app/controllers/spend_forecasts_controller.rb +++ b/app/controllers/spend_forecasts_controller.rb @@ -24,6 +24,22 @@ def update end end + def create + if spend_forecast.update(spend_forecast_params) + redirect_to spend_forecast_path(spend_forecast) + else + render :new, status: :unprocessable_entity + end + end + + def create + if spend_forecast.update(spend_forecast_params) + redirect_to spend_forecast_path(spend_forecast) + else + render :new, status: :unprocessable_entity + end + end + def show;end def download_budget_csv @@ -47,9 +63,4 @@ def spend_forecast_params temp_params.merge!(budget: process_csv(params[:spend_forecast][:budget_file])) if params[:spend_forecast][:budget_file] temp_params end - - def process_csv(file) - require 'csv' - CSV.read(file.path, headers: true) - end end diff --git a/app/models/spend_forecast.rb b/app/models/spend_forecast.rb index 7bdafe3..b914d2b 100644 --- a/app/models/spend_forecast.rb +++ b/app/models/spend_forecast.rb @@ -8,7 +8,7 @@ class SpendForecast < ApplicationRecord validates :status, presence: true, inclusion: { in: STATUSES } validate :end_date_after_start_date - attr_accessor :budget_file + attr_accessor :budget_file, :rows_lost enum status: STATUSES.index_by(&:to_sym) diff --git a/app/views/spend_forecasts/_form.html.erb b/app/views/spend_forecasts/_form.html.erb index 5d6ca74..1304d1d 100644 --- a/app/views/spend_forecasts/_form.html.erb +++ b/app/views/spend_forecasts/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for spend_forecast do |f| %> +<%= form_for spend_forecast, id: 'spend_forecast', html: { data: { controller: "budget-file", budget_file_target: "form", budget_file_user_id: user.id } } do |f| %> <% if @spend_forecast.errors.any? %>