Sha256: 9dc95d1ddd56cfa3a5517ebec6b1d1beff0cce2999afcd12a3c43723dd02327d

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

class Gamification::InventoriesController < ApplicationController
  before_action :set_gamification_inventory, only: [:show, :edit, :update, :destroy]
  before_action :set_user, only: [:update]

  # GET /gamification/inventories
  def index
    @gamification_inventories = Gamification::Inventory.all
  end

  # GET /gamification/inventories/1
  def show
  end

  # GET /gamification/inventories/new
  def new
    @gamification_inventory = Gamification::Inventory.new
  end

  # GET /gamification/inventories/1/edit
  def edit
  end

  # POST /gamification/inventories
  def create
    @gamification_inventory = Gamification::Inventory.new(inventory_params)

    if @gamification_inventory.save
      redirect_to @gamification_inventory, notice: 'Inventory was successfully created.'
    else
      render :new
    end
  end

  # PATCH/PUT /gamification/inventories/1
  def update
    respond_to do |format|
      if @gamification_inventory.equip_item(params[:user_id].to_i)

        format.js
        format.json { head :no_content }
      else
        format.js
        format.json { render json: @gamification_inventory.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /gamification/inventories/1
  def destroy
    @gamification_inventory.destroy
    redirect_to gamification_inventories_url, notice: 'Inventory was successfully destroyed.'
  end

  private
  # Use callbacks to share common setup or constraints between actions.
  def set_gamification_inventory
    @gamification_inventory = Gamification::Inventory.find(params[:id])
  end

  def set_user
    @user = User.find(params[:user_id])
  end

  # Only allow a trusted parameter "white list" through.

  def inventory_params
    params.require(:inventory).permit(:user_id, :equipped, :gamification_item_id)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
go_gamification-0.0.17 app/controllers/gamification/inventories_controller.rb