Merge pull request #608 from basecamp/create-and-add-another

Add multiple cards quickly
This commit is contained in:
Jorge Manrubia
2025-06-13 08:58:35 +02:00
committed by GitHub
4 changed files with 24 additions and 3 deletions
+1
View File
@@ -175,6 +175,7 @@
.btn--reversed {
--btn-background: var(--color-canvas);
--btn-color: var(--card-color);
--btn-border-color: var(--color-container);
}
}
@@ -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
@@ -1,4 +1,5 @@
<div class="card-perma__notch card-perma__notch--bottom">
<%= button_to "Create card", card_publish_path(card), class: "btn" %>
<%= button_to "Save as draft", collection_card_path(card.collection, card), name: "card[status]", value: "drafted", method: :put, class: "btn btn--reversed" %>
<%= 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>
@@ -15,4 +15,17 @@ class Cards::PublishesControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to card
end
test "create and add another" do
card = cards(:logo)
card.drafted!
assert_changes -> { card.reload.published? }, from: false, to: true do
assert_difference -> { Card.creating.count }, +1 do
post card_publish_path(card, creation_type: "add_another")
end
end
assert_redirected_to Card.creating.last
end
end