This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= turbo_stream.remove "item_1" %> | |
<%= turbo_stream.update "stats" do %> | |
<%= render "items/stats" %> | |
<% end %> | |
<%= turbo_stream.update "flash", partial: "layouts/flash" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "@hotwired/stimulus" | |
export default class ResultsToggle extends Controller { | |
// --- | |
// Targets | |
static targets = ["elementToHide"] | |
// --- | |
// Values | |
static values = { visible: Boolean } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
# Returns a new hash with the nil values/key pairs removed recursively. | |
# | |
# hash = { a: true, b: { c: [1, 2, 3], d: { e: nil, f: 4 } }, g: nil } | |
# | |
# hash.deep_compact # => { a: true, b: { c: [1, 2, 3], d: { f: 4 } } } | |
def deep_compact | |
dup.deep_compact! | |
end |