Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
cavy / app / controllers / cavy / items_controller.rb
Size: Mime:
require_dependency "cavy/application_controller"

module Cavy
  class ItemsController < ApplicationController

    before_action :set_item, only: [:show, :edit, :update, :destroy]
    before_action :set_group, only: [:create,:update]

    layout 'cavy/admin_layout'

    # GET /items/1
    def show
    end

    # GET /items/new
    def new
      @group = Cavy::ItemGroup.find_by(id: params[:group_id])
      @item = @group.items.new
      @item.create_params(@group.title,@group.params)
    end

    # GET /items/1/edit
    def edit
    end

    # POST /items
    def create
      @group = Cavy::ItemGroup.find_by(id: params[:group_id])
      @item = @group.items.create(params[:item])

      if @item.save
        redirect_to cavy_item_group_path(params[:group_id]), notice: 'Item was successfully created.'
      end
    end

    # PATCH/PUT /items/1
    def update
      if @item.update_attributes(params[:item])
        redirect_to cavy_item_path(@item.id), notice: 'Item was successfully updated.'
      end
    end

    # DELETE /items/1
    def destroy
      @item.destroy
      redirect_to :back, notice: 'Item was successfully destroyed.'
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_item
        @item = Item.find(params[:id])
      end

      def set_group
        if @item
          params['item']['data']['type'] = @item.data['type']
        else
          params['item']['data']['type'] = Cavy::ItemGroup.find(params[:group_id]).type
        end
      end

  end
end