Lab 7 Review by harley · Pull Request #5 · coderschool/CoderStore · GitHub
Skip to content
This repository was archived by the owner on Nov 29, 2020. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
11 changes: 7 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ group :development, :test do
gem 'faker'
gem 'rspec-rails'
end
group :production do
gem 'rails_12factor'
end
group :test do
gem 'capybara', '~> 2.7.1'
gem 'capybara', '~> 2.10', '>= 2.10.1'
gem 'database_cleaner'
gem 'launchy'
gem 'selenium-webdriver'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'carrierwave'
gem 'carrierwave-aws'
gem 'carrierwave-postgresql'
gem 'mini_magick'
gem 'dotenv-rails', groups: [:development, :test], require: 'dotenv/rails-now'
gem 'postgresql_lo_streamer'
42 changes: 34 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ GEM
autoprefixer-rails (6.1.1)
execjs
json
aws-sdk (2.5.4)
aws-sdk-resources (= 2.5.4)
aws-sdk-core (2.5.4)
jmespath (~> 1.0)
aws-sdk-resources (2.5.4)
aws-sdk-core (= 2.5.4)
bcrypt (3.1.11)
better_errors (2.1.1)
coderay (>= 1.0.0)
Expand All @@ -55,13 +61,24 @@ GEM
sass (>= 3.3.4)
builder (3.2.3)
byebug (8.2.0)
capybara (2.7.1)
capybara (2.10.1)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
carrierwave (0.11.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
mimemagic (>= 0.3.0)
carrierwave-aws (1.0.1)
aws-sdk (~> 2.0)
carrierwave (~> 0.7)
carrierwave-postgresql (0.1.5)
carrierwave
childprocess (0.5.8)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.0)
Expand All @@ -82,6 +99,10 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.2.5)
dotenv (2.1.1)
dotenv-rails (2.1.1)
dotenv (= 2.1.1)
railties (>= 4.0, < 5.1)
erubis (2.7.0)
execjs (2.6.0)
factory_girl (4.7.0)
Expand Down Expand Up @@ -114,6 +135,7 @@ GEM
jbuilder (2.5.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jmespath (1.3.1)
jquery-rails (4.1.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand All @@ -133,6 +155,8 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mimemagic (0.3.2)
mini_magick (4.5.1)
mini_portile2 (2.1.0)
minitest (5.10.1)
multi_json (1.11.2)
Expand All @@ -145,6 +169,8 @@ GEM
shellany (~> 0.0)
orm_adapter (0.5.0)
pg (0.18.4)
postgresql_lo_streamer (1.1.0)
rails (>= 4.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand All @@ -170,12 +196,7 @@ GEM
nokogiri (~> 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_layout (1.0.29)
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.4)
railties (5.0.2)
actionpack (= 5.0.2)
activesupport (= 5.0.2)
Expand Down Expand Up @@ -277,10 +298,14 @@ DEPENDENCIES
better_errors
bootstrap-sass
byebug
capybara (~> 2.7.1)
capybara (~> 2.10, >= 2.10.1)
carrierwave
carrierwave-aws
carrierwave-postgresql
coffee-rails (~> 4.2)
database_cleaner
devise
dotenv-rails
factory_girl_rails
faker
guard-rspec
Expand All @@ -289,10 +314,11 @@ DEPENDENCIES
jquery-rails
launchy
listen (~> 3.0.5)
mini_magick
pg
postgresql_lo_streamer
puma (~> 3.0)
rails (~> 5.0, >= 5.0.2)
rails_12factor
rails_layout
rspec-rails
sass-rails (~> 5.0)
Expand Down
50 changes: 2 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
Coderstore
CoderStore
================

[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

This application was generated with the [rails_apps_composer](https://github.com/RailsApps/rails_apps_composer) gem
provided by the [RailsApps Project](http://railsapps.github.io/).

Rails Composer is supported by developers who purchase our RailsApps tutorials.

Problems? Issues?
-----------

Need help? Ask on Stack Overflow with the tag 'railsapps.'

Your application contains diagnostics in the README file. Please provide a copy of the README file when reporting any issues.

If the application doesn't work as expected, please [report an issue](https://github.com/RailsApps/rails_apps_composer/issues)
and include the diagnostics.

Ruby on Rails
-------------

This application requires:

- Ruby 2.2.1
- Rails 4.2.5

Learn more about [Installing Rails](http://railsapps.github.io/installing-rails.html).

Getting Started
---------------

Documentation and Support
-------------------------

Issues
-------------

Similar Projects
----------------

Contributing
------------

Credits
-------

License
-------
Starter app for CoderSchool Lab3.
2 changes: 2 additions & 0 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PhotosController < ApplicationController
end
20 changes: 20 additions & 0 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ProductsController < ApplicationController
def new
@product = Product.new
end

def create
@product = Product.new product_params
if @product.save
redirect_to root_path, alert: 'Success.'
else
render 'new'
end
end

private

def product_params
params.require(:product).permit(:name, :description, :image_path, :image, :thumbnail)
end
end
2 changes: 2 additions & 0 deletions app/helpers/photos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PhotosHelper
end
2 changes: 2 additions & 0 deletions app/helpers/products_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ProductsHelper
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
3 changes: 3 additions & 0 deletions app/models/photo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Photo < ApplicationRecord
belongs_to :product
end
8 changes: 8 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
class Product < ActiveRecord::Base
mount_uploader :image, ImageUploader
mount_uploader :thumbnail, ThumbnailUploader
validates :name, presence: true
has_many :photos

def image_path_or_image
image_path.presence || image
end
end
54 changes: 54 additions & 0 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base

# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick

# Choose what kind of storage to use for this uploader:
# storage :file
# storage :fog

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model_id}"
end

def model_id
model ? model.id : 'no-model'
end

# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fit => [50, 50]
end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end

end
51 changes: 51 additions & 0 deletions app/uploaders/thumbnail_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# encoding: utf-8

class ThumbnailUploader < CarrierWave::Uploader::Base

# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick

# Choose what kind of storage to use for this uploader:
storage :postgresql_lo
# storage :fog

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end

# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
# version :thumb do
# process :resize_to_fit => [50, 50]
# end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end

end
14 changes: 10 additions & 4 deletions app/views/products/_product.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<%= image_tag product.image_path %>
<%= image_tag product.image_path_or_image %>
<div class="caption">
<h4 class="pull-right"><%= product.price_vnd %></h4>
<h4><a href="#"><%= product.name %></a>
</h4>
<p><%= product.description %></p>
<h4 class="product-name"><a href="#"><%= product.name %></a></h4>
<div>
<p>
<% if product.thumbnail.url %>
<%= image_tag product.thumbnail.url %>
<% end %>
<%= product.description %>
</p>
</div>
</div>
<div class="ratings">
<p class="pull-right">15 reviews</p>
Expand Down
22 changes: 22 additions & 0 deletions app/views/products/new.html.slim
Loading