Skip to content

Commit

Permalink
Add destroy link in the show template
Browse files Browse the repository at this point in the history
  • Loading branch information
shouichi committed Feb 16, 2022
1 parent 6939dbe commit 212146e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/assets/stylesheets/administrate/components/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ input[type="submit"],
background-color: $action-color;
}
}

&--danger {
@extend .button;
background-color: $red;

&:hover {
background-color: mix($black, $red, 20%);
color: $white;
}
}
}

.button--alt {
Expand Down
8 changes: 8 additions & 0 deletions app/views/administrate/application/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ as well as a link to its edit page.
[:edit, namespace, page.resource],
class: "button",
) if valid_action?(:edit) && show_action?(:edit, page.resource) %>

<%= link_to(
t("administrate.actions.destroy"),
[namespace, page.resource],
class: "button--danger",
method: :delete,
data: { confirm: t("administrate.actions.confirm") }
) if valid_action?(:destroy) && show_action?(:destroy, page.resource) %>
</div>
</header>

Expand Down
8 changes: 8 additions & 0 deletions spec/features/show_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@
expect(page).to have_header("Edit #{displayed(customer)}")
end

it "displays destroy link" do
customer = create(:customer)

visit admin_customer_path(customer)

expect { click_on "Destroy" }.to change(Customer, :count).from(1).to(0)
end

it "displays translated labels" do
custom_label = "Newsletter Subscriber"
customer = create(:customer)
Expand Down

0 comments on commit 212146e

Please sign in to comment.