diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..599c1a0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true diff --git a/app/assets/javascripts/books.coffee b/app/assets/javascripts/books.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/books.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/books.scss b/app/assets/stylesheets/books.scss new file mode 100644 index 0000000..9fab565 --- /dev/null +++ b/app/assets/stylesheets/books.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000..e2e8383 --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,21 @@ +class BooksController < ApplicationController + def index + @books = Book.all + end + def new + @book = Book.new + end + def create + @book = Book.new(book_params) + if @book.save + redirect_to books_path, + notice: "Book was created successfully" + else + render :new + end + end +private + def book_params + params.require(:book).permit :title, :connet, :author + end +end \ No newline at end of file diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000..4b9311e --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000..03d56b4 --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,2 @@ +class Book < ApplicationRecord +end diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb new file mode 100644 index 0000000..acb758c --- /dev/null +++ b/app/views/books/_form.html.erb @@ -0,0 +1,9 @@ +<%= form_for book do |form| %> +
<%= form.label :title, value: "Title" %>
+
<%= form.text_field :title %>
+
<%= form.label :content, value: "Content" %>
+
<%= form.text_area :content %>
+
<%= form.label :author, value: "Author" %>
+
<%= form.text_field :author %>
+
<%= form.submit %>
+<% end %> \ No newline at end of file diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000..4f47951 --- /dev/null +++ b/app/views/books/index.html.erb @@ -0,0 +1,9 @@ +
    + <% @books.each do |book| %> +
  • <%= book.id %>
  • +
  • <%= book.title %>
  • +
  • <%= book.content %>
  • +
  • <%= book.author %>
  • + <% end %> +
+<%= link_to "New book", new_book_path %> \ No newline at end of file diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000..9e93a79 --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,3 @@ +

New Book

+<%= render "form", book: @book %> +<%= link_to "Back", books_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 787824f..49c563c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ Rails.application.routes.draw do + resources :books, only: [:index, :new, :create] # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20180114131154_create_books.rb b/db/migrate/20180114131154_create_books.rb new file mode 100644 index 0000000..1c3a9ad --- /dev/null +++ b/db/migrate/20180114131154_create_books.rb @@ -0,0 +1,11 @@ +class CreateBooks < ActiveRecord::Migration[5.1] + def change + create_table :books do |t| + t.string :title + t.text :content + t.string :author + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..7010883 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,23 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20180114131154) do + + create_table "books", force: :cascade do |t| + t.string "title" + t.text "content" + t.string "author" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/test/controllers/books_controller_test.rb b/test/controllers/books_controller_test.rb new file mode 100644 index 0000000..d8c4306 --- /dev/null +++ b/test/controllers/books_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BooksControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/books.yml b/test/fixtures/books.yml new file mode 100644 index 0000000..80aed36 --- /dev/null +++ b/test/fixtures/books.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/book_test.rb b/test/models/book_test.rb new file mode 100644 index 0000000..e48079d --- /dev/null +++ b/test/models/book_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BookTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end