Skip to content

Commit

Permalink
Move logic to SessionWindow controller (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
janpeterka authored Sep 29, 2024
1 parent 728f778 commit 865ad09
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
11 changes: 0 additions & 11 deletions app/controllers/spectator_sport/dashboard/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ class DashboardsController < ApplicationController
def index
@session_windows = SessionWindow.order(:created_at).limit(50).reverse_order
end

def show
@session_window = SessionWindow.find(params[:id])
end

def destroy
@session_window = SessionWindow.find(params[:id])
@session_window.events.delete_all
@session_window.delete
redirect_to action: :index
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SpectatorSport
module Dashboard
class SessionWindowsController < ApplicationController
def show
@session_window = SessionWindow.find(params[:id])
end

def destroy
@session_window = SessionWindow.find(params[:id])
@session_window.events.delete_all
@session_window.delete

redirect_to "/spectator_sport_dashboard"
end
end
end
end
4 changes: 2 additions & 2 deletions app/views/spectator_sport/dashboard/dashboards/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<% @session_windows.each do |session_window| %>
<li>
<%= link_to "Session (##{session_window.session_id}) Window (##{session_window.id})", dashboard_path(session_window.id) %>
<%= button_to "X", { action: :destroy, id: session_window.id }, method: :delete, form: { style: "display: inline-block" } %>
<%= link_to "Session (##{session_window.session_id}) Window (##{session_window.id})", session_window_path(session_window.id) %>
<%= button_to "X", session_window, method: :delete, form: { style: "display: inline-block" } %>
</li>
<% end %>
</ul>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

SpectatorSport::Dashboard::Engine.routes.draw do
get "/", to: "dashboards#index"
resources :dashboards, only: [ :show, :destroy ]
# resources :dashboards, only: [ :show, :destroy ]
resources :session_windows, only: [ :show, :destroy ]
end

0 comments on commit 865ad09

Please sign in to comment.