Skip to content

Commit

Permalink
feat: broadcast replace appointments with a lazy turbo frame
Browse files Browse the repository at this point in the history
  • Loading branch information
avogel3 committed Jan 27, 2025
1 parent 1abc785 commit ce38709
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/models/appointment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ class Appointment < ApplicationRecord

validates :requested_datetime, presence: true

after_save_commit -> {
broadcast_replace_to(
"appointments_list",
partial: "appointments/load_row",
locals: { appointment: self }
)
}

def created_by?(user)
created_by == user
end
Expand Down
1 change: 1 addition & 0 deletions app/views/appointments/_load_row.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= turbo_frame_tag(appointment, src: row_appointment_path(appointment)) %>
1 change: 1 addition & 0 deletions app/views/appointments/row.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render "appointment", appointment: %>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Rails.application.routes.draw do
resource :session
resources :passwords, param: :token
resources :appointments, only: [:index, :edit, :update]
resources :appointments, only: [:index, :edit, :update] do

Check failure on line 4 in config/routes.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 4 in config/routes.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
member do
get :row
end
end
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
Expand Down

0 comments on commit ce38709

Please sign in to comment.