diff --git a/app/controllers/admin/content_modules/games_controller.rb b/app/controllers/admin/content_modules/games_controller.rb new file mode 100644 index 0000000..82f917c --- /dev/null +++ b/app/controllers/admin/content_modules/games_controller.rb @@ -0,0 +1,33 @@ +class Admin::ContentModules::GamesController < AdminController + before_action :set_content_module + + def new + @content = @content_module.contents.build + load_game_options + end + + def create + @content = @content_module.contents.build(contentable: Game.find_by(id: content_params[:contentable_id])) + + if @content.save + redirect_to edit_admin_content_module_path(@content_module), notice: "Game was successfully added." + else + load_game_options + render :new, status: :unprocessable_entity + end + end + + private + def set_content_module + @content_module = ContentModule.find(params.expect(:content_module_id)) + end + + def load_game_options + @available_games = Game.available_for(@content_module) + @any_games = Game.exists? + end + + def content_params + params.expect(content: [ :contentable_id ]) + end +end diff --git a/app/views/admin/content_modules/edit.html.erb b/app/views/admin/content_modules/edit.html.erb index cfe4a6f..6f47207 100644 --- a/app/views/admin/content_modules/edit.html.erb +++ b/app/views/admin/content_modules/edit.html.erb @@ -23,6 +23,7 @@
All games are in this module.
+ <% else %> ++ No games yet. + <%= link_to "Create a game", new_admin_game_path, class: "link" %> +
+ <% end %> + <%= link_to "Back to module", edit_admin_content_module_path(@content_module), class: "link text-sm" %> +