Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logic to SessionWindow controller #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy with this, but spectator_sport_dashboard_path didn't work. I probably don't completely understand routing in context of Engines, so I didn't find a way to not use absolute path (which is not great).
Maybe you know how to improve this, @bensheldon ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for flagging that, I totally overlooked that. As you're probably aware, it's not great because the routes could be mounted at a different path by the parent application.

I also struggled with some of the routing stuff. I think the problem may be that Engines are not intended to be namespace nested. This is the first gem I've done with 2 engines, which I believe is necessary to mount the client-api separately from the dashboard. I'll poke it some more and figure out a way forward.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! I think it's simply because each engine is separately loading routes.rb, so it loads twice. Lemme fix that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, I think 😓 #8

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