From 31c851aa5b8a21be5985844cdb7655d0738e65c3 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Fri, 13 Jun 2025 08:55:30 +0200 Subject: [PATCH] Use the same controller for publishing cards and for publishing and adding another --- app/controllers/cards/publishes_controller.rb | 8 +++++++- app/controllers/cards_controller.rb | 5 ----- app/views/cards/container/footer/_draft.html.erb | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/cards/publishes_controller.rb b/app/controllers/cards/publishes_controller.rb index f7ac6590c..cd24ffdeb 100644 --- a/app/controllers/cards/publishes_controller.rb +++ b/app/controllers/cards/publishes_controller.rb @@ -3,6 +3,12 @@ class Cards::PublishesController < ApplicationController def create @card.publish - redirect_to @card + + redirect_to add_another_param? ? @collection.cards.create! : @card end + + private + def add_another_param? + params[:creation_type] == "add_another" + end end diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index 660cd7513..8a8b4fb05 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -15,11 +15,6 @@ class CardsController < ApplicationController end def create - if params[:publish_current] - @card = Card.find(params[:publish_current]) - @card.publish - flash[:notice] = "Card added" - end card = @collection.cards.create! redirect_to card end diff --git a/app/views/cards/container/footer/_draft.html.erb b/app/views/cards/container/footer/_draft.html.erb index 2e58b978b..7b3dff00a 100644 --- a/app/views/cards/container/footer/_draft.html.erb +++ b/app/views/cards/container/footer/_draft.html.erb @@ -1,5 +1,5 @@
- <%= button_to "Create card", card_publish_path(card), class: "btn" %> - <%= button_to "Create and add another", collection_cards_path(card.collection, publish_current: card.id), method: :post, class: "btn btn--reversed", form: { data: { turbo: false } } %> + <%= button_to "Create card", card_publish_path(card), name: "creation_type", value: "add", class: "btn" %> + <%= button_to "Create and add another", card_publish_path(card), method: :post, class: "btn btn--reversed", name: "creation_type", value: "add_another", form: { data: { turbo: false } } %> <%= button_to "Save as a draft", collection_card_path(card.collection, card), name: "card[status]", value: "drafted", method: :put, class: "btn btn--reversed" %>