Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
3 changes: 3 additions & 0 deletions app/assets/javascripts/books.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/books.scss
Original file line number Diff line number Diff line change
@@ -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/
21 changes: 21 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/books_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BooksHelper
end
2 changes: 2 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Book < ApplicationRecord
end
9 changes: 9 additions & 0 deletions app/views/books/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= form_for book do |form| %>
<div><%= form.label :title, value: "Title" %><div>
<div><%= form.text_field :title %><div>
<div><%= form.label :content, value: "Content" %><div>
<div><%= form.text_area :content %><div>
<div><%= form.label :author, value: "Author" %><div>
<div><%= form.text_field :author %><div>
<div><%= form.submit %><div>
<% end %>
9 changes: 9 additions & 0 deletions app/views/books/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul>
<% @books.each do |book| %>
<li><%= book.id %></li>
<li><%= book.title %></li>
<li><%= book.content %></li>
<li><%= book.author %></li>
<% end %>
</ul>
<%= link_to "New book", new_book_path %>
3 changes: 3 additions & 0 deletions app/views/books/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>New Book</h1>
<%= render "form", book: @book %>
<%= link_to "Back", books_path %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions db/migrate/20180114131154_create_books.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/controllers/books_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class BooksControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
11 changes: 11 additions & 0 deletions test/fixtures/books.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/models/book_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class BookTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end