Skip to content

Instantly share code, notes, and snippets.

View results_toggle_controller.js
import { Controller } from "@hotwired/stimulus"
export default class ResultsToggle extends Controller {
// ---
// Targets
static targets = ["elementToHide"]
// ---
// Values
static values = { visible: Boolean }
View index.html.erb
<%= turbo_frame_tag "results" do %>
<section data-controller="results-toggle"
data-results-toggle-visible-value="true"
data-results-toggle-hidden-class="hidden">
<button data-action="click->results-toggle#toggle">Hide Results</button>
<div data-results-toggle-target="elementToHide">
<% @items.each do |item| %>
<%= render item %>
@SofiaSousa
SofiaSousa / destroy.turbo_stream.erb
Last active Aug 9, 2022
destroy.turbo_stream.erb
View destroy.turbo_stream.erb
<%= turbo_stream.remove "item_1" %>
<%= turbo_stream.update "stats" do %>
<%= render "items/stats" %>
<% end %>
<%= turbo_stream.update "flash", partial: "layouts/flash" %>
View index.html.erb
<section>
<%= form_with(url: items_path, method: :get) do |f| %>
...
<%= f.submit "Search" %>
<% end %>
<%= turbo_frame_tag "results" do %>
<% @items.each do |item| %>
<%= render item %>
<% end %>