Files
BreakEscape/app/controllers/break_escape/application_controller.rb
Z. Cliffe Schreuders e18950c6d7 feat: Configure dummy app for development with engine migrations
- Add root route that redirects to missions list
- Fix ApplicationController to fallback to demo user when current_user unavailable
- Configure dummy app to load engine migrations in application.rb
- Create test/dummy/db/migrate directory
- Successfully migrated and seeded database with 26 missions

Now visiting http://localhost:3000 will show the missions selection page!
2025-11-21 15:27:54 +00:00

36 lines
1.0 KiB
Ruby

module BreakEscape
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
# Include Pundit if available
include Pundit::Authorization if defined?(Pundit)
# Helper method to get current player (polymorphic)
def current_player
if BreakEscape.standalone_mode? || !respond_to?(:current_user, true)
# Standalone mode or no current_user available - get/create demo user
@current_player ||= DemoUser.first_or_create!(handle: 'demo_player')
else
# Mounted mode - use Hacktivity's current_user
current_user
end
end
helper_method :current_player
# Tell Pundit to use current_player as the user for authorization
def pundit_user
current_player
end
# Handle authorization errors
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
private
def user_not_authorized
flash[:alert] = "You are not authorized to perform this action."
redirect_to(request.referrer || root_path)
end
end
end