Class: SimpleText::DocumentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- SimpleText::DocumentsController
- Defined in:
- app/controllers/simple_text/documents_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
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 |
#edit ⇒ Object
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 |
#index ⇒ Object
3 4 5 |
# File 'app/controllers/simple_text/documents_controller.rb', line 3 def index @documents = Document.all.page params[:page] end |
#new ⇒ Object
15 16 17 |
# File 'app/controllers/simple_text/documents_controller.rb', line 15 def new @document = Document.new end |
#show ⇒ Object
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 |
#update ⇒ Object
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 |