Class: Hicube::DocumentsController

Inherits:
BaseController show all
Defined in:
app/controllers/hicube/documents_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::FLASH_TYPES

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #notify, #notify_now

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/hicube/documents_controller.rb', line 22

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

#destroyObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/hicube/documents_controller.rb', line 39

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

#editObject



51
52
# File 'app/controllers/hicube/documents_controller.rb', line 51

def edit
end

#indexObject



54
55
# File 'app/controllers/hicube/documents_controller.rb', line 54

def index
end

#showObject



57
58
# File 'app/controllers/hicube/documents_controller.rb', line 57

def show
end

#updateObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/hicube/documents_controller.rb', line 60

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