Commit e805d506 by Tan Phat Nguyen

CRUD product on venshop

parent c12cbfc4
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rails', '4.2.0.beta4'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'carrierwave', '0.10.0'
gem 'rails', '4.1.7' gem 'mini_magick', '3.8.0'
# Use sqlite3 as the database for Active Record gem 'fog', '1.23.0'
gem 'sqlite3' gem 'bcrypt', '3.1.7'
# Use SCSS for stylesheets gem 'faker', '1.4.2'
gem 'sass-rails', '~> 4.0.3' gem 'will_paginate', '3.0.7'
# Use Uglifier as compressor for JavaScript assets gem 'bootstrap-will_paginate', '0.0.10'
gem 'uglifier', '>= 1.3.0' gem 'bootstrap-sass', '3.2.0.0'
# Use CoffeeScript for .js.coffee assets and views gem 'unicorn', '4.8.3'
gem 'coffee-rails', '~> 4.0.0' gem 'sass-rails', '5.0.0.beta1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes gem 'uglifier', '2.5.3'
# gem 'therubyracer', platforms: :ruby gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '4.0.0.beta2'
# Use jquery as the JavaScript library gem 'turbolinks', '2.3.0'
gem 'jquery-rails' gem 'jbuilder', '2.2.3'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'rails-html-sanitizer', '1.0.1'
gem 'turbolinks' gem 'sdoc', '0.4.0', group: :doc
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'mysql2' gem 'mysql2'
gem 'vacuum' gem 'vacuum'
# Use ActiveModel has_secure_password group :development, :test do
# gem 'bcrypt', '~> 3.1.7' gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
# Use unicorn as the app server gem 'web-console', '2.0.0.beta3'
# gem 'unicorn' gem 'spring', '1.1.3'
end
# Use Capistrano for deployment group :test do
# gem 'capistrano-rails', group: :development gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
gem 'shoulda'
end
# Use debugger group :production do
# gem 'debugger', group: [:development, :test] gem 'rails_12factor', '0.0.2'
gem 'unicorn', '4.8.3'
end
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actionmailer (4.1.7) actionmailer (4.2.0.beta4)
actionpack (= 4.1.7) actionpack (= 4.2.0.beta4)
actionview (= 4.1.7) actionview (= 4.2.0.beta4)
activejob (= 4.2.0.beta4)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
actionpack (4.1.7) rails-dom-testing (~> 1.0, >= 1.0.4)
actionview (= 4.1.7) actionpack (4.2.0.beta4)
activesupport (= 4.1.7) actionview (= 4.2.0.beta4)
rack (~> 1.5.2) activesupport (= 4.2.0.beta4)
rack (~> 1.6.0.beta)
rack-test (~> 0.6.2) rack-test (~> 0.6.2)
actionview (4.1.7) rails-dom-testing (~> 1.0, >= 1.0.4)
activesupport (= 4.1.7) rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0.beta4)
activesupport (= 4.2.0.beta4)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubis (~> 2.7.0)
activemodel (4.1.7) rails-dom-testing (~> 1.0, >= 1.0.4)
activesupport (= 4.1.7) rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0.beta4)
activesupport (= 4.2.0.beta4)
globalid (>= 0.3.0)
activemodel (4.2.0.beta4)
activesupport (= 4.2.0.beta4)
builder (~> 3.1) builder (~> 3.1)
activerecord (4.1.7) activerecord (4.2.0.beta4)
activemodel (= 4.1.7) activemodel (= 4.2.0.beta4)
activesupport (= 4.1.7) activesupport (= 4.2.0.beta4)
arel (~> 5.0.0) arel (>= 6.0.0.beta2, < 6.1)
activesupport (4.1.7) activesupport (4.2.0.beta4)
i18n (~> 0.6, >= 0.6.9) i18n (>= 0.7.0.beta1, < 0.8)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.1) thread_safe (~> 0.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (5.0.1.20140414130214) ansi (1.4.3)
arel (6.0.0.beta2)
bcrypt (3.1.7)
bcrypt (3.1.7-x64-mingw32)
binding_of_caller (0.7.3.pre1)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.2.0.0)
sass (~> 3.2)
bootstrap-will_paginate (0.0.10)
will_paginate
builder (3.2.2) builder (3.2.2)
byebug (3.4.0)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
celluloid (0.16.0)
timers (~> 4.0.0)
coderay (1.1.0)
coffee-rails (4.0.1) coffee-rails (4.0.1)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
...@@ -36,95 +66,236 @@ GEM ...@@ -36,95 +66,236 @@ GEM
coffee-script-source coffee-script-source
execjs execjs
coffee-script-source (1.8.0) coffee-script-source (1.8.0)
columnize (0.8.9)
debug_inspector (0.0.2)
debugger-linecache (1.2.0)
erubis (2.7.0) erubis (2.7.0)
excon (0.41.0) excon (0.41.0)
execjs (2.2.2) execjs (2.2.2)
faker (1.4.2)
i18n (~> 0.5)
ffi (1.9.6)
ffi (1.9.6-x64-mingw32)
fog (1.23.0)
fog-brightbox
fog-core (~> 1.23)
fog-json
fog-softlayer
ipaddress (~> 0.5)
nokogiri (~> 1.5, >= 1.5.11)
fog-brightbox (0.6.1)
fog-core (~> 1.22)
fog-json
inflecto
fog-core (1.24.0)
builder
excon (~> 0.38)
formatador (~> 0.2)
mime-types
net-scp (~> 1.1)
net-ssh (>= 2.1.3)
fog-json (1.0.0)
multi_json (~> 1.0)
fog-softlayer (0.3.24)
fog-core
fog-json
formatador (0.2.5)
globalid (0.3.0)
activesupport (>= 4.1.0)
guard (2.8.2)
formatador (>= 0.2.4)
listen (~> 2.7)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-minitest (2.3.1)
guard (~> 2.0)
minitest (>= 3.0)
hike (1.2.3) hike (1.2.3)
i18n (0.6.11) hitimes (1.2.2)
jbuilder (2.2.4) i18n (0.7.0.beta1)
inflecto (0.0.2)
ipaddress (0.8.0)
jbuilder (2.2.3)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
jeff (1.1.0) jeff (1.1.0)
excon (>= 0.22.1) excon (>= 0.22.1)
jquery-rails (3.1.2) jquery-rails (4.0.0.beta2)
railties (>= 3.0, < 5.0) rails-dom-testing (~> 1.0)
railties (>= 4.2.0.beta, < 5.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.1) json (1.8.1)
kgio (2.9.2)
listen (2.7.11)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
loofah (2.0.1)
nokogiri (>= 1.5.9)
lumberjack (1.0.9)
mail (2.6.3) mail (2.6.3)
mime-types (>= 1.16, < 3) mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.4.3) mime-types (2.4.3)
mini_backtrace (0.1.3)
minitest (> 1.2.0)
rails (>= 2.3.3)
mini_magick (3.8.0)
subexec (~> 0.2.1)
mini_portile (0.6.1)
minitest (5.4.2) minitest (5.4.2)
minitest-reporters (1.0.5)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.10.1) multi_json (1.10.1)
multi_xml (0.5.5) multi_xml (0.5.5)
mysql2 (0.3.16) mysql2 (0.3.16)
rack (1.5.2) net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
nokogiri (1.6.4.1)
mini_portile (~> 0.6.0)
nokogiri (1.6.4.1-x64-mingw32)
mini_portile (~> 0.6.0)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry (0.10.1-x64-mingw32)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
win32console (~> 1.3)
rack (1.6.0.beta)
rack-test (0.6.2) rack-test (0.6.2)
rack (>= 1.0) rack (>= 1.0)
rails (4.1.7) rails (4.2.0.beta4)
actionmailer (= 4.1.7) actionmailer (= 4.2.0.beta4)
actionpack (= 4.1.7) actionpack (= 4.2.0.beta4)
actionview (= 4.1.7) actionview (= 4.2.0.beta4)
activemodel (= 4.1.7) activejob (= 4.2.0.beta4)
activerecord (= 4.1.7) activemodel (= 4.2.0.beta4)
activesupport (= 4.1.7) activerecord (= 4.2.0.beta4)
activesupport (= 4.2.0.beta4)
bundler (>= 1.3.0, < 2.0) bundler (>= 1.3.0, < 2.0)
railties (= 4.1.7) railties (= 4.2.0.beta4)
sprockets-rails (~> 2.0) sprockets-rails (~> 3.0.0.beta1)
railties (4.1.7) rails-deprecated_sanitizer (1.0.3)
actionpack (= 4.1.7) activesupport (>= 4.2.0.alpha)
activesupport (= 4.1.7) rails-dom-testing (1.0.4)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
loofah (~> 2.0)
rails_12factor (0.0.2)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.2)
rails_stdout_logging (0.0.3)
railties (4.2.0.beta4)
actionpack (= 4.2.0.beta4)
activesupport (= 4.2.0.beta4)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
raindrops (0.13.0)
rake (10.3.2) rake (10.3.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rdoc (4.1.2) rdoc (4.1.2)
json (~> 1.4) json (~> 1.4)
sass (3.2.19) ruby-progressbar (1.7.0)
sass-rails (4.0.4) sass (3.4.7)
sass-rails (5.0.0.beta1)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
sass (~> 3.2.2) sass (~> 3.2)
sprockets (~> 2.8, < 2.12) sprockets (~> 2.12)
sprockets-rails (~> 2.0) sprockets-rails (>= 2.0, < 4.0)
sdoc (0.4.1) sdoc (0.4.0)
json (~> 1.7, >= 1.7.7) json (~> 1.8)
rdoc (~> 4.0) rdoc (~> 4.0, < 5.0)
sprockets (2.11.3) shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.7.0)
activesupport (>= 3.0.0)
slop (3.6.0)
spring (1.1.3)
sprockets (2.12.3)
hike (~> 1.2) hike (~> 1.2)
multi_json (~> 1.0) multi_json (~> 1.0)
rack (~> 1.0) rack (~> 1.0)
tilt (~> 1.1, != 1.3.0) tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.0) sprockets-rails (3.0.0.beta1)
actionpack (>= 3.0) actionpack (>= 4.0)
activesupport (>= 3.0) activesupport (>= 4.0)
sprockets (>= 2.8, < 4.0) sprockets (~> 2.8)
sqlite3 (1.3.10) sqlite3 (1.3.9)
sqlite3 (1.3.10-x64-mingw32) sqlite3 (1.3.9-x64-mingw32)
subexec (0.2.3)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.4) thread_safe (0.3.4)
tilt (1.4.1) tilt (1.4.1)
turbolinks (2.5.1) timers (4.0.1)
hitimes
turbolinks (2.3.0)
coffee-rails coffee-rails
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.5.3) uglifier (2.5.3)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
unicorn (4.8.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
vacuum (1.1.1) vacuum (1.1.1)
jeff (~> 1.0) jeff (~> 1.0)
multi_xml (~> 0.5.0) multi_xml (~> 0.5.0)
web-console (2.0.0.beta3)
activemodel (~> 4.0)
binding_of_caller (= 0.7.3.pre1)
railties (~> 4.0)
sprockets-rails (>= 2.0, < 4.0)
will_paginate (3.0.7)
win32console (1.3.2)
PLATFORMS PLATFORMS
ruby ruby
x64-mingw32 x64-mingw32
DEPENDENCIES DEPENDENCIES
coffee-rails (~> 4.0.0) bcrypt (= 3.1.7)
jbuilder (~> 2.0) bootstrap-sass (= 3.2.0.0)
jquery-rails bootstrap-will_paginate (= 0.0.10)
byebug (= 3.4.0)
carrierwave (= 0.10.0)
coffee-rails (= 4.0.1)
faker (= 1.4.2)
fog (= 1.23.0)
guard-minitest (= 2.3.1)
jbuilder (= 2.2.3)
jquery-rails (= 4.0.0.beta2)
mini_backtrace (= 0.1.3)
mini_magick (= 3.8.0)
minitest-reporters (= 1.0.5)
mysql2 mysql2
rails (= 4.1.7) rails (= 4.2.0.beta4)
sass-rails (~> 4.0.3) rails-html-sanitizer (= 1.0.1)
sdoc (~> 0.4.0) rails_12factor (= 0.0.2)
sqlite3 sass-rails (= 5.0.0.beta1)
turbolinks sdoc (= 0.4.0)
uglifier (>= 1.3.0) shoulda
spring (= 1.1.3)
sqlite3 (= 1.3.9)
turbolinks (= 2.3.0)
uglifier (= 2.5.3)
unicorn (= 4.8.3)
vacuum vacuum
web-console (= 2.0.0.beta3)
will_paginate (= 3.0.7)
# 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/
$(document).ready ->
$('#product_photo').bind 'change', ->
size_in_megabytes = this.files[0].size/1024/1024
if (size_in_megabytes > 5)
alert('Maximum file size is 5MB. Please choose a smaller file.')
\ No newline at end of file
@import "bootstrap-sprockets";
@import "bootstrap";
/* mixins, variables, etc. */
$gray-medium-light: #eaeaea;
@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $gray-light;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: white;
text-transform: uppercase;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
&:hover {
color: white;
text-decoration: none;
}
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid $gray-medium-light;
color: $gray-light;
a {
color: $gray;
&:hover {
color: $gray-darker;
}
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 15px;
}
}
}
/* sidebar */
aside {
section.user_info {
margin-top: 20px;
}
section {
padding: 10px 0;
margin-top: 20px;
&:first-child {
border: 0;
padding-top: 0;
}
span {
display: block;
margin-bottom: 3px;
line-height: 1;
}
h1 {
font-size: 1.4em;
text-align: left;
letter-spacing: -1px;
margin-bottom: 3px;
margin-top: 0px;
}
}
}
.gravatar {
float: left;
margin-right: 10px;
}
.gravatar_edit {
margin-top: 15px;
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
@include box_sizing;
}
input {
height: auto !important;
}
#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}
.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}
.checkbox {
margin-top: -10px;
margin-bottom: 10px;
span {
margin-left: 20px;
font-weight: normal;
}
}
#session_remember_me {
width: auto;
margin-left: 0;
}
/* Users index */
.users {
list-style: none;
margin: 0;
li {
overflow: auto;
padding: 10px 0;
border-bottom: 1px solid $gray-lighter;
}
}
/* microposts */
.microposts {
list-style: none;
padding: 0;
li {
padding: 10px 0;
border-top: 1px solid #e8e8e8;
}
.user {
margin-top: 5em;
padding-top: 0;
}
.content {
display: block;
margin-left: 60px;
img {
display: block;
padding: 5px 0;
}
}
.timestamp {
color: $gray-light;
display: block;
margin-left: 60px;
}
.gravatar {
float: left;
margin-right: 10px;
margin-top: 5px;
}
}
aside {
textarea {
height: 100px;
margin-bottom: 5px;
}
}
span.picture {
margin-top: 10px;
input {
border: 0;
}
}
\ No newline at end of file
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
def index
@products = Product.all
end
def new
@product = Product.new
end
def create
@product = Product.new(product_params)
if @product.save
redirect_to @product
else
render 'new'
end
end
def show
end
def edit
end
def update
if @product.update_attributes(product_params)
redirect_to @product
else
render 'edit'
end
end
def destroy
@product.destroy
redirect_to products_path
end
private
def product_params
params.require(:product).permit(:name, :price, :description, :category_id, :photo)
end
def set_product
@product = Product.find(params[:id])
end
end
module ProductsHelper
end
class Category < ActiveRecord::Base class Category < ActiveRecord::Base
has_many :products, dependent: :destroy
end end
class Product < ActiveRecord::Base class Product < ActiveRecord::Base
belongs_to :category belongs_to :category
validates :name, presence: true, length: { maximum: 50 }
validate :photo_size
mount_uploader :photo, ImageUploader
private
def photo_size
if photo.size > 5.megabytes
errors.add(:photo, "should be less than 5MB")
end
end
end end
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_limit: [400, 400]
# 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 extension_white_list
%w(jpg jpeg gif png)
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
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Demo</title> <title>Venshop</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
......
<%= form_for @product do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= image_tag @product.photo.url %> <br>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :price %>
<%= f.text_field :price, class: 'form-control' %>
<%= f.label :description %>
<%= f.text_area :description, class: 'form-control' %>
<%= f.label :category %>
<%= f.select :category_id, Category.all.collect { |category| [category.name, category.id] } %>
<%= f.file_field :photo, accept: 'image/jpeg,image/gif,image/png' %>
<%= f.submit class: "btn btn-primary" %>
<% end %>
\ No newline at end of file
<tr>
<td><%= product.name %></td>
<td><%= product.price %></td>
<td><%= product.description %></td>
<td><%= product.category.name %></td>
<td><%= image_tag product.photo_url.to_s %></td>
<td><%= link_to 'Show', product_path(product) %></td>
<td><%= link_to 'Edit', edit_product_path(product) %></td>
<td><%= link_to 'Destroy', product_path(product), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<h1>Edit Product</h1>
<%= render 'form' %>
\ No newline at end of file
<h1>Welcome to Venshop</h1>
<table class='table'>
<tr>
<th>Name</th>
<th>Price</th>
<th>Description</th>
<th>Category</th>
<th>Photo</th>
<th colspan='3'></th>
</tr>
<%= render @products %>
</table>
<%= link_to 'New Product', new_product_path %>
<h1>Add New Product</h1>
<%= render partial: 'products/form', locals: { product: @product } %>
\ No newline at end of file
<h1>Show Product</h1>
<p>Name: <b><%= @product.name%></b></p>
<p>Price: <b><%= @product.price%></b></p>
<p>Description: <b><%= @product.description%></b></p>
<p>Category: <b><%= @product.category.name%></b></p>
<%= image_tag @product.photo.url %> <br/>
<%= link_to 'Back', products_path %>
| <%= link_to 'Edit', edit_product_path(@product) %>
\ No newline at end of file
<% if object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(object.errors.count, "error") %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
\ No newline at end of file
...@@ -3,58 +3,6 @@ Rails.application.routes.draw do ...@@ -3,58 +3,6 @@ Rails.application.routes.draw do
get 'amazon/index' get 'amazon/index'
# The priority is based upon order of creation: first created -> highest priority. resources :products
# See how all your routes lay out with "rake routes". root 'products#index'
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end end
class AddImageToProducts < ActiveRecord::Migration
def change
add_column :products, :photo, :string
end
end
...@@ -11,21 +11,22 @@ ...@@ -11,21 +11,22 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141110030316) do ActiveRecord::Schema.define(version: 20141110093259) do
create_table "categories", force: true do |t| create_table "categories", force: true do |t|
t.string "name" t.string "name", limit: 255
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "products", force: true do |t| create_table "products", force: true do |t|
t.string "name" t.string "name", limit: 255
t.decimal "price", precision: 10, scale: 0 t.decimal "price", precision: 10
t.text "description" t.text "description", limit: 65535
t.integer "category_id" t.integer "category_id", limit: 4
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "photo", limit: 255
end end
add_index "products", ["category_id"], name: "index_products_on_category_id", using: :btree add_index "products", ["category_id"], name: "index_products_on_category_id", using: :btree
......
require 'test_helper'
class ProductControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class ProductsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class ProductHelperTest < ActionView::TestCase
end
require 'test_helper'
class ProductsHelperTest < ActionView::TestCase
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment