diff --git a/app/controllers/calculators_controller.rb b/app/controllers/calculators_controller.rb index 4402a8969..78753bfa2 100644 --- a/app/controllers/calculators_controller.rb +++ b/app/controllers/calculators_controller.rb @@ -22,6 +22,9 @@ def calculate @results = Calculators::CalculationService.new(@calculator, params[:inputs]).perform + session[:calculation_results] ||= {} + session[:calculation_results][@calculator.slug] = @results + respond_to :turbo_stream end diff --git a/app/views/calculators/show.html.erb b/app/views/calculators/show.html.erb index 489f4f024..a0c1fb0f7 100644 --- a/app/views/calculators/show.html.erb +++ b/app/views/calculators/show.html.erb @@ -10,12 +10,16 @@ <% else %> <%= form.select "inputs[#{field.var_name}]", options_from_collection_for_select(field.categories, :price, :name) %> <% end %> -
+ +
<% end %>
<%= form.submit "Calculate", class: "bg-blue-500 text-white font-semibold px-4 py-2 rounded hover:bg-blue-700" %>
<% end %> - - <%= turbo_frame_tag "calc-results" %> + <%= turbo_frame_tag "calc-results" do %> + <% if session.dig(:calculation_results, @calculator.slug)&.presence %> + <%= render "calculators/partials/calculation_results", results: session[:calculation_results][@calculator.slug].map(&:symbolize_keys) %> + <% end %> + <% end %>