Created
March 16, 2021 02:49
-
-
Save ag0os/cd3eb4514493675946692d2b660478dd to your computer and use it in GitHub Desktop.
Building Hotwire Kanban
This file contains hidden or 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
# /views/cards/_card.html.erb | |
<%= turbo_frame_tag dom_id(@card) do %> | |
<div class="card card-body"> | |
<div><%= @card.title %></div> | |
</div> | |
<% end %> |
This file contains hidden or 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
# /views/columns/_column.html.erb | |
<%= turbo_stream_from "cards" %> | |
<%= turbo_frame_tag dom_id(column) do %> | |
<div class="col-sm border border-secondary"> | |
<div class="row border border-primary"><%= column.name %></div> | |
<div class="row"> | |
<div class="col-12"> | |
<%= turbo_frame_tag 'cards' do %> | |
<% column.cards.each do |card| %> | |
<%= turbo_frame_tag dom_id(card), src: board_column_card_path(@board, column, card) do %> | |
<div class="card card-body"> | |
loading... | |
</div> | |
<% end %> | |
<% end %> | |
<% end %> | |
</div> | |
</div> | |
</div> | |
<% end %> |
This file contains hidden or 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
# /views/boards/show.html.erb | |
<div class="container"> | |
<p id="notice"><%= notice %></p> | |
<%= turbo_stream_from "columns" %> | |
<div class="row"> | |
<%= turbo_frame_tag "columns" do %> | |
<%= render @columns %> | |
<% end %> | |
</div> | |
</div> |
This file contains hidden or 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 Card < ApplicationRecord | |
belongs_to :column | |
after_create_commit { broadcast_append_to "cards" } | |
after_update_commit { broadcast_replace_to "cards" } | |
after_destroy_commit { broadcast_remove_to "cards" } | |
validates :title, presence: true | |
end |
This file contains hidden or 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
# /views/cards/show.html.erb | |
<%= render "card", card: @card %> |
This file contains hidden or 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 Column < ApplicationRecord | |
belongs_to :board | |
has_many :cards, dependent: :destroy | |
after_create_commit { broadcast_append_to "columns" } | |
# after_update_commit { broadcast_replace_to "columns" } | |
after_destroy_commit { broadcast_remove_to "columns" } | |
end |
This file contains hidden or 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
Rails.application.routes.draw do | |
resources :boards do | |
resources :columns do | |
resources :cards | |
end | |
end | |
root to: "boards#index" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment