Sha256: edcc0d3ac763d17982713a0b58eef274bed24ec0aca89ea50d3d807c5532d4cc

Contents?: true

Size: 1.88 KB

Versions: 11

Compression:

Stored size: 1.88 KB

Contents

require_dependency "hicube/application_controller"

module Hicube
  class DocumentsController < BaseController

    before_action :load_resource, except: [
      :create,
      :index,
      :new
    ]

    before_filter :load_resources, :only => [
      :index,
    ]

    # Must be called after load_recource filter.
    before_filter :check_resource_params, :only => [
      :create,
      :update,
    ]

    def create
      @document = Document.new document_params.except(:tags)
      document_params[:tags].split(' ').each do |s|
        @document.tags << Hicube::Tag.find_or_create_by(name: s)
      end

      @document.save!

      respond_to do |format|
        notify :notice, ::I18n.t('messages.resource.created',
          type:       Hicube::Document.model_name.human,
          resource:   @document
        )
        format.html { redirect_to action: :index }
      end
    end

    def destroy
      @document.destroy

      respond_to do |format|
        notify :warning, ::I18n.t('messages.resource.destroyed',
          type:       Hicube::Document.model_name.human,
          resource:   @document
        )
        format.html { redirect_to action: :index }
      end
    end

    def edit
    end
    
    def index
    end

    def show
    end
    
    def update  
      @document.update_attributes document_params.except(:tags)
      
      @document.tags = nil
      params[:document][:tags].split(' ').each do |s|
        @document.tags << Hicube::Tag.find_or_create_by(name: s)
      end

      @document.save!

      respond_to do |format|
        notify :notice, ::I18n.t('messages.resource.updated',
          type:       Hicube::Document.model_name.human,
          resource:   @document
        )
        format.html { redirect_to action: :index }
      end
     end
    
    private

    def document_params
      params.require(:document).permit(:name, :file, :tags)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hicube-0.0.11 app/controllers/hicube/documents_controller.rb
hicube-0.0.10 app/controllers/hicube/documents_controller.rb
hicube-0.0.9 app/controllers/hicube/documents_controller.rb
hicube-0.0.8 app/controllers/hicube/documents_controller.rb
hicube-0.0.7 app/controllers/hicube/documents_controller.rb
hicube-0.0.6 app/controllers/hicube/documents_controller.rb
hicube-0.0.5 app/controllers/hicube/documents_controller.rb
hicube-0.0.4 app/controllers/hicube/documents_controller.rb
hicube-0.0.3 app/controllers/hicube/documents_controller.rb
hicube-0.0.2 app/controllers/hicube/documents_controller.rb
hicube-0.0.1 app/controllers/hicube/documents_controller.rb