Class: SimpleText::DocumentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/simple_text/documents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @document = Document.create create_params

  respond_to do |format|
    if @document.save
      create_edit_entry @document, :a_create
      format.html { redirect_to documents_path, notice: t('simple_text.created') }
    else
      format.html { render new_document_path, notice: t('simple_text.error') }
    end
  end
end

#editObject



32
33
34
# File 'app/controllers/simple_text/documents_controller.rb', line 32

def edit
  @document = Document.where(name: params[:id]).first || not_found
end

#indexObject



3
4
5
# File 'app/controllers/simple_text/documents_controller.rb', line 3

def index
  @documents = Document.all.page params[:page]
end

#newObject



15
16
17
# File 'app/controllers/simple_text/documents_controller.rb', line 15

def new
  @document = Document.new
end

#showObject



7
8
9
10
11
12
13
# File 'app/controllers/simple_text/documents_controller.rb', line 7

def show
  @document = Document.where(name: params[:name]).first || not_found

  unless fresh_when(etag: @document, last_modified: @document.created_at, public: true)
    render
  end
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/simple_text/documents_controller.rb', line 36

def update
  @document = Document.where(name: params[:document][:name]).first || not_found
  _old_doc = @document.clone
  respond_to do |format|
    if @document.update permit_params
      create_edit_entry @document, :a_update, _old_doc.as_json.to_s
      format.html { redirect_to documents_path, notice: t('simple_text.succeeded') }
    else
      format.html { render 'edit' }
    end
  end
end