Class: Admin::DocumentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/documents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/admin/documents_controller.rb', line 17

def create  #loop on each file from array and create document

  params[:document][:filearrays].each do |file|
    @document = Document.new(:document => file, :documentable_id => params[:document][:documentable_id], :documentable_type => params[:document][:documentable_type], :organization_id => current_user.organization.id)
    if @document.save
      flash[:notice] = 'Successfully uploaded the document.'
    else
      flash[:error] = 'There was a problem uploading the document.'
    end
  end
  
  redirect_to :back
end

#destroyObject


31
32
33
34
35
36
37
# File 'app/controllers/admin/documents_controller.rb', line 31

def destroy
  @document = Document.find(params[:id])
  @document.destroy
  flash[:notice] = 'Successfully destroyed document.'
  
  redirect_to :back
end

#indexObject


6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/admin/documents_controller.rb', line 6

def index
  if params[:animal_id]
    @search = Document.organization(current_user).where(documentable_id: params[:animal_id], documentable_type: 'Animal').search(params[:q])
  else
    @search = Document.organization(current_user).search(params[:q])
  end
  @documents = @search.result.paginate(:page => params[:page], :per_page => 10).order("updated_at DESC")

  respond_with(@documents)
end