Sha256: e89cdb27cd889fca8e9a112f9fc4ea01a1f4d98fd5fb8f33483b2c34800f0d68

Contents?: true

Size: 1.54 KB

Versions: 10

Compression:

Stored size: 1.54 KB

Contents

module Tenon
  class ItemVersionsController < Tenon::BaseController
    respond_to :html, :json

    def create
      @item_version = ItemVersion.new(resource_params)
      item_params = @item_version.item_type.gsub('Tenon::', '').underscore
      @item_version.attrs = params[item_params]
      @item_version.creator_id = current_user.id
      @item_version.save
      respond_to do |format|
        format.json { render status: 200, nothing: true }
      end
    end

    def new
      @item_version = ItemVersion.new(
        item_id: params[:item_id],
        item_type: params[:item_type]
      )

      respond_to do |format|
        format.html { render layout: false }
      end
    end

    def index
      respond_to do |format|
        # Modal
        format.html { render layout: false }

        format.json do
          params.delete(:item_id) if params[:item_id] == ''
          @item_versions = ItemVersion
            .where(params.slice(:item_type, :item_id).permit!)
            .paginate(page: params[:page], per_page: 5)

          serializer = ActiveModel::Serializer.serializer_for(ItemVersion.new)
          respond_with(
            @item_versions,
            serializer: Tenon::PaginatingSerializer,
            each_serializer: serializer,
            root: 'records',
            serialization_scope: view_context
          )
        end
      end
    end

    private

    def resource_params
      params.require(:item_version).permit!
    end

    def default_serializer_options
      { root: 'record', scope: view_context }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tenon-2.1.0 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.8 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.7 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.6 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.5 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.4 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.3 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.2 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.1 app/controllers/tenon/item_versions_controller.rb
tenon-2.0.0 app/controllers/tenon/item_versions_controller.rb