Sha256: 5d1a4d9529c03edcf0a77a0a9ffcb5f97275f7a139da858f41db2c3be445ff6c

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

class IshManager::MapsController < IshManager::ApplicationController

  before_action :set_map, only: [:show, :edit, :update, :destroy]

  def index
    authorize! :index, ::Gameui::Map
    @maps = ::Gameui::Map.all
  end

  def show
    authorize! :show, @map
  end

  def new
    authorize! :new, ::Gameui::Map
    @map = ::Gameui::Map.new
  end

  def edit
    authorize! :edit, @map
  end

  def create
    @map = ::Gameui::Map.new(map_params)
    if map_params[:parent_slug].present?
      @map.parent = ::Gameui::Map.find_by({ slug: map_params[:parent_slug] })
    end
    authorize! :create, @map

    respond_to do |format|
      if @map.save
        format.html { redirect_to map_path(@map), notice: 'Map was successfully created.' }
      else
        format.html { render :new }
      end
    end
  end

  def update
    authorize! :update, @map
    respond_to do |format|
      if map_params[:parent_slug].present?
        @map.parent = ::Gameui::Map.find_by({ slug: map_params[:parent_slug] })
      else
        @map.parent = nil
      end
      if @map.update(map_params)
        format.html { redirect_to map_path(@map), notice: 'Map was successfully updated.' }
      else
        format.html { render :edit }
      end
    end
  end

  def destroy
    authorize! :destroy, @map
    @map.destroy
    respond_to do |format|
      format.html { redirect_to maps_path, notice: 'Map was successfully destroyed.' }
    end
  end

  private

    def set_map
      @map = ::Gameui::Map.find(params[:id])
    end

    def map_params
      params.require(:gameui_map).permit!
    end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ish_manager-0.1.8.249 app/controllers/ish_manager/maps_controller.rb
ish_manager-0.1.8.248 app/controllers/ish_manager/maps_controller.rb
ish_manager-0.1.8.247 app/controllers/ish_manager/maps_controller.rb