Use the same controller for publishing cards and for publishing and adding another

This commit is contained in:
Jorge Manrubia
2025-06-13 08:55:30 +02:00
parent 75d9ce0b82
commit 31c851aa5b
3 changed files with 9 additions and 8 deletions
@@ -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
-5
View File
@@ -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
@@ -1,5 +1,5 @@
<div class="card-perma__notch card-perma__notch--bottom">
<%= 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" %>
</div>