ozfortress/citadel

View on GitHub
app/controllers/meta/maps_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Meta
  class MapsController < MetaController
    skip_before_action :require_any_admin_permissions, only: [:show]
    skip_before_action :require_meta, only: [:show]

    before_action(except: [:index, :new, :create]) { @map = Map.find(params[:id]) }

    def index
      @maps = Map.all
    end

    def new
      @map = Map.new
    end

    def create
      @map = Map.new(map_params)

      if @map.save
        redirect_to meta_map_path(@map)
      else
        render :new
      end
    end

    def show
    end

    def edit
    end

    def update
      if @map.update(map_params)
        redirect_to meta_map_path(@map)
      else
        render :edit
      end
    end

    def destroy
      if @map.destroy
        redirect_to meta_game_path(@map.game)
      else
        render :edit
      end
    end

    private

    def map_params
      params.require(:map).permit(:game_id, :name, :description)
    end
  end
end