Skip to content

Commit 977de3a

Browse files
committed
Allow for arbitrary pages mitre-cyber-academy#380
This makes it so users can put custom pages in ``app/views/arbitrary/`` to have their page show up on the navbar.
1 parent 9afc3b4 commit 977de3a

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

app/controllers/application_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ApplicationController < ActionController::Base
88
before_action :store_user_location, if: :storable_location?
99
before_action :set_paper_trail_whodunnit
1010
before_action :configure_permitted_parameters, if: :devise_controller?
11+
before_action :set_arbitrary_pages
1112
helper :all
1213

1314
def user_root_path
@@ -63,6 +64,10 @@ def prevent_action_after_game
6364

6465
private
6566

67+
def set_arbitrary_pages
68+
@arbitrary_pages = Dir['app/views/arbitrary/*']
69+
end
70+
6671
def preload_helper(*preload_objects)
6772
pl = ActiveRecord::Associations::Preloader.new
6873
preload_objects.filter! do |table|

app/views/layouts/_navbar.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
= always_link_to_if_admin(@game.open?, t('application.navbar.summary'), game_summary_path)
1919
%li
2020
= link_to_unless(@game.contact_url.blank?, t('application.navbar.contact'), @game.contact_url, target: '_blank'){}
21+
- if @arbitrary_pages.any?
22+
- @arbitrary_pages.each do |page|
23+
%li= link_to File.basename(page, ".*").split('.').first.capitalize, '/arbitrary/' + File.basename(page, ".*")

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
66

77
get 'home/index'
8+
get '/arbitrary/:page' => 'arbitrary#show'
89

910
devise_for :users,
1011
path_names: { sign_in: 'login', sign_out: 'logout', confirmation: 'confirm', sign_up: 'new' },

0 commit comments

Comments
 (0)