diff --git a/.gitignore b/.gitignore index 89ad058..a556f6d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ config/application.yml # Ignore Sqlite DB db/*.sqlite3 +# Ignore image files attachments +/public/system diff --git a/Gemfile b/Gemfile index d7d99ed..a4cb226 100644 --- a/Gemfile +++ b/Gemfile @@ -18,14 +18,18 @@ gem 'coffee-rails', '~> 4.2' gem 'jquery-rails' gem 'turbolinks', '~> 5' gem 'jbuilder', '~> 2.5' + group :development, :test do gem 'byebug', platform: :mri end group :development do + gem 'better_errors' + gem 'binding_of_caller' gem 'web-console', '>= 3.3.0' gem 'listen', '~> 3.0.5' gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end + gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock index ff77988..f647f19 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,7 +42,13 @@ GEM autoprefixer-rails (7.1.4.1) execjs bcrypt (3.1.11) + better_errors (2.4.0) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) bindex (0.5.0) + binding_of_caller (0.7.3) + debug_inspector (>= 0.0.1) bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) @@ -51,6 +57,7 @@ GEM climate_control (0.2.0) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) + coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -60,12 +67,14 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.0.5) crass (1.0.2) + debug_inspector (0.0.3) devise (4.3.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0, < 5.2) responders warden (~> 1.2.3) + erubi (1.7.0) erubis (2.7.0) execjs (2.7.0) ffi (1.9.18) @@ -191,6 +200,8 @@ PLATFORMS ruby DEPENDENCIES + better_errors + binding_of_caller bootstrap-sass (~> 3.3, >= 3.3.6) byebug coffee-rails (~> 4.2) diff --git a/app/assets/images/.keep b/app/assets/images/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/app/models/book.rb b/app/models/book.rb index 2b878a5..5c879d7 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -2,6 +2,6 @@ class Book < ApplicationRecord belongs_to :user belongs_to :category has_many :reviews - has_attached_file :book_img, styles: { book_index: "300x300>", book_show: "325x475>" }, default_url: "/images/:style/missing.png" + has_attached_file :book_img, styles: { book_index: "300x300>", book_show: "325x475>" }, default_url: "/images/missing.png" validates_attachment_content_type :book_img, content_type: /\Aimage\/.*\z/ end diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2a..01f1428 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,40 @@ # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) + +categories_names = ["Fantasy", "Technology", "Biography", "Fiction"] +categories_names.each do |category_name| + Category.find_or_create_by(name: category_name) +end +puts 'Categories seeded.' + +user_1 = User.where(email: 'user_1@example.org').first_or_create!( + password: 'test123', + password_confirmation: 'test123' +) + +user_2 = User.where(email: 'user_2@example.org').first_or_create!( + password: 'test123', + password_confirmation: 'test123' +) +puts 'Users seeded.' + +categories = Category.first(10) +(0..2).to_a.each do |category_index| + category = categories[category_index] + (1..3).to_a.each do |number| + book = Book.where(title: "Book #{number}", category_id: category.id).first_or_create!( + description: "Description of Book in category #{category.name}", + author: 'Author of Book', + user: user_1 + ) + + if book.reviews.empty? + book.reviews.create([ + { rating: rand(5), comment: 'Comment for Book', user: user_1 }, + { rating: rand(5), comment: 'Comment for Book', user: user_2 } + ]) + end + end +end +puts 'Books and Reviews seeded.' diff --git a/public/images/missing.png b/public/images/missing.png new file mode 100644 index 0000000..7af2ee1 Binary files /dev/null and b/public/images/missing.png differ diff --git a/public/system/books/book_imgs/000/000/004/book_index/download_(1).jpeg b/public/system/books/book_imgs/000/000/004/book_index/download_(1).jpeg deleted file mode 100644 index 032cf89..0000000 Binary files a/public/system/books/book_imgs/000/000/004/book_index/download_(1).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/004/book_show/download_(1).jpeg b/public/system/books/book_imgs/000/000/004/book_show/download_(1).jpeg deleted file mode 100644 index 032cf89..0000000 Binary files a/public/system/books/book_imgs/000/000/004/book_show/download_(1).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/004/original/download_(1).jpeg b/public/system/books/book_imgs/000/000/004/original/download_(1).jpeg deleted file mode 100644 index 13de1d6..0000000 Binary files a/public/system/books/book_imgs/000/000/004/original/download_(1).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/005/book_index/download_(2).jpeg b/public/system/books/book_imgs/000/000/005/book_index/download_(2).jpeg deleted file mode 100644 index 93d779e..0000000 Binary files a/public/system/books/book_imgs/000/000/005/book_index/download_(2).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/005/book_show/download_(2).jpeg b/public/system/books/book_imgs/000/000/005/book_show/download_(2).jpeg deleted file mode 100644 index 93d779e..0000000 Binary files a/public/system/books/book_imgs/000/000/005/book_show/download_(2).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/005/original/download_(2).jpeg b/public/system/books/book_imgs/000/000/005/original/download_(2).jpeg deleted file mode 100644 index 5bfce26..0000000 Binary files a/public/system/books/book_imgs/000/000/005/original/download_(2).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/006/book_index/download_(3).jpeg b/public/system/books/book_imgs/000/000/006/book_index/download_(3).jpeg deleted file mode 100644 index 1544b2a..0000000 Binary files a/public/system/books/book_imgs/000/000/006/book_index/download_(3).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/006/book_show/download_(3).jpeg b/public/system/books/book_imgs/000/000/006/book_show/download_(3).jpeg deleted file mode 100644 index 1544b2a..0000000 Binary files a/public/system/books/book_imgs/000/000/006/book_show/download_(3).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/006/original/download_(3).jpeg b/public/system/books/book_imgs/000/000/006/original/download_(3).jpeg deleted file mode 100644 index 615b160..0000000 Binary files a/public/system/books/book_imgs/000/000/006/original/download_(3).jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/007/book_index/download.jpeg b/public/system/books/book_imgs/000/000/007/book_index/download.jpeg deleted file mode 100644 index af59359..0000000 Binary files a/public/system/books/book_imgs/000/000/007/book_index/download.jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/007/book_show/download.jpeg b/public/system/books/book_imgs/000/000/007/book_show/download.jpeg deleted file mode 100644 index af59359..0000000 Binary files a/public/system/books/book_imgs/000/000/007/book_show/download.jpeg and /dev/null differ diff --git a/public/system/books/book_imgs/000/000/007/original/download.jpeg b/public/system/books/book_imgs/000/000/007/original/download.jpeg deleted file mode 100644 index 33e2a4c..0000000 Binary files a/public/system/books/book_imgs/000/000/007/original/download.jpeg and /dev/null differ