From 1ee30c0bb7914a092125e66722a77f6cb0e23789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 23 Apr 2024 23:12:30 +0200 Subject: [PATCH] Remove the create action from CommentableActions We were only using it in one place: the debates controller. All the other controllers including CommentableActions were overwriting this action, except the ones in the admin area, where creating proposals, debates or investments isn't possible. Note this means that, most of the times, we weren't tracking events creating a resource. Also note that since, as mentioned in commit 3752fef6b, there are no geozones in the debates form, we don't have to load them when creating a debate fails due to validation rules. --- app/controllers/concerns/commentable_actions.rb | 15 --------------- app/controllers/debates_controller.rb | 12 ++++++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index a4bc77a4d..8a47f509e 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -44,21 +44,6 @@ module CommentableActions @resources = @search_terms.present? ? resource_relation.search(@search_terms) : nil end - def create - @resource = resource_model.new(strong_params) - @resource.author = current_user - - if @resource.save - track_event - redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id) - redirect_to redirect_path, notice: t("flash.actions.create.#{resource_name.underscore}") - else - load_geozones - set_resource_instance - render :new - end - end - def edit end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 33c7fd899..e2b1a1efb 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -19,6 +19,18 @@ class DebatesController < ApplicationController helper_method :resource_model, :resource_name respond_to :html, :js + def create + @debate = Debate.new(debate_params) + @debate.author = current_user + + if @debate.save + track_event + redirect_to debate_path(@debate), notice: t("flash.actions.create.debate") + else + render :new + end + end + def index_customization @featured_debates = @debates.featured end