diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 37636e7..9128939 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -1,2 +1,25 @@ class DocumentsController < ApplicationController + def index + @documents_grid = initialize_grid(Document) + end + + def new + @document = Document.new + end + + def create + @document = Document.new(document_params) + + if @document.save + redirect_to documents_path, notice: 'Document was successfully created.' + else + lash.now[:alert] = 'Document creation failed.' + render 'new' + end + end + +private + def document_params + params.require(:document).permit(:name) + end end diff --git a/app/models/document.rb b/app/models/document.rb index 46a330f..35ccdfe 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -1,2 +1,3 @@ class Document < ActiveRecord::Base + validates :name, presence: true end diff --git a/app/views/documents/_form.html.slim b/app/views/documents/_form.html.slim new file mode 100644 index 0000000..6ccd960 --- /dev/null +++ b/app/views/documents/_form.html.slim @@ -0,0 +1,4 @@ += bootstrap_form_for(@document) do |f| + = f.text_field :name + + = f.submit \ No newline at end of file diff --git a/app/views/documents/_grid.html.erb b/app/views/documents/_grid.html.erb new file mode 100644 index 0000000..59d663a --- /dev/null +++ b/app/views/documents/_grid.html.erb @@ -0,0 +1,5 @@ +<%= grid(@documents_grid, upper_pagination_panel: true) do |g| + g.column name: 'ID', attribute: 'id' + g.column name: 'Name', attribute: 'name' + end +%> \ No newline at end of file diff --git a/app/views/documents/index.html.slim b/app/views/documents/index.html.slim index 6c4a5ac..4087099 100644 --- a/app/views/documents/index.html.slim +++ b/app/views/documents/index.html.slim @@ -1 +1,6 @@ -| Hallo \ No newline at end of file +h1 Index + +p + = btn_link_to 'New', new_document_path, class: 'btn-primary' + += render 'grid' diff --git a/app/views/documents/new.html.slim b/app/views/documents/new.html.slim new file mode 100644 index 0000000..feebdc4 --- /dev/null +++ b/app/views/documents/new.html.slim @@ -0,0 +1 @@ +== render 'form' \ No newline at end of file