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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ config/application.yml
# Ignore Sqlite DB
db/*.sqlite3

# Ignore image files attachments
/public/system
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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]
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -191,6 +200,8 @@ PLATFORMS
ruby

DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3, >= 3.3.6)
byebug
coffee-rails (~> 4.2)
Expand Down
Empty file removed app/assets/images/.keep
Empty file.
2 changes: 1 addition & 1 deletion app/models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 37 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Binary file added public/images/missing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.