Commit 2a52ca08 by Dao Minh Nhut

create index page, create model cart

parent 193525ad
...@@ -25,10 +25,10 @@ gem 'sdoc', '~> 0.4.0', group: :doc ...@@ -25,10 +25,10 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password # Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7' # gem 'bcrypt', '~> 3.1.7'
gem 'will_paginate'
# Use Unicorn as the app server # Use Unicorn as the app server
# gem 'unicorn' # gem 'unicorn'
gem 'bootstrap-will_paginate'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
......
...@@ -46,6 +46,8 @@ GEM ...@@ -46,6 +46,8 @@ GEM
bootstrap-sass (3.3.5.1) bootstrap-sass (3.3.5.1)
autoprefixer-rails (>= 5.0.0.1) autoprefixer-rails (>= 5.0.0.1)
sass (>= 3.3.0) sass (>= 3.3.0)
bootstrap-will_paginate (0.0.10)
will_paginate
builder (3.2.2) builder (3.2.2)
byebug (5.0.0) byebug (5.0.0)
columnize (= 0.9.0) columnize (= 0.9.0)
...@@ -162,12 +164,14 @@ GEM ...@@ -162,12 +164,14 @@ GEM
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
railties (>= 4.0) railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
will_paginate (3.0.7)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
bootstrap-sass bootstrap-sass
bootstrap-will_paginate
byebug byebug
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
devise devise
...@@ -182,6 +186,7 @@ DEPENDENCIES ...@@ -182,6 +186,7 @@ DEPENDENCIES
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
vacuum vacuum
web-console (~> 2.0) web-console (~> 2.0)
will_paginate
BUNDLED WITH BUNDLED WITH
1.10.5 1.10.5
# 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/
# 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/
...@@ -13,3 +13,5 @@ ...@@ -13,3 +13,5 @@
*= require_tree . *= require_tree .
*= require_self *= require_self
*/ */
@import "bootstrap-sprockets";
@import "bootstrap";
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
// Place all the styles related to the Cart controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the Cart_Product controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
...@@ -66,7 +66,7 @@ h2 { ...@@ -66,7 +66,7 @@ h2 {
margin-bottom: 30px; margin-bottom: 30px;
text-align: center; text-align: center;
font-weight: normal; font-weight: normal;
color: $fff; color: white;
} }
p { p {
......
class CartController < ApplicationController
def new
end
end
class CartProductController < ApplicationController
def new
end
end
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@products = Product.all @products = Product.paginate(page: params[:page])
end end
end end
...@@ -6,7 +6,8 @@ class ProductsController < ApplicationController ...@@ -6,7 +6,8 @@ class ProductsController < ApplicationController
#@item = Product.find(params[:id]) #@item = Product.find(params[:id])
#end #end
def index def index
@item = Product.find(:all) @item = Product.all
@categories = Category.all
#@items = Product.all.select do |i| #@items = Product.all.select do |i|
#i.category==params[:id] #i.category==params[:id]
#end #end
......
module CartHelper
end
module CartProductHelper
end
class Cart < ActiveRecord::Base
end
class CartProduct < ActiveRecord::Base
end
<h1>Cart#new</h1>
<p>Find me in app/views/cart/new.html.erb</p>
<h1>CartProduct#new</h1>
<p>Find me in app/views/cart_product/new.html.erb</p>
<ul class="products"> <div class="navbar navbar-inverse navbar-fixed-top">
<% @products.each do |product| %> <div class="navbar-inner">
<div class="container">
<button class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="/">RWM</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">E-Commerce <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="index.html">E-commerce</a></li>
<li><a href="ecommerce-item.html">E-commerce Item</a></li>
<li><a href="ecommerce-cart.html">E-commerce Cart</a></li>
<li><a href="ecommerce-checkout.html">E-commerce Checkout</a></li>
</ul>
</li>
</ul>
<form class="navbar-form form-search pull-right">
<input id="Search" name="Search" type="text" placeholder="type text to search for" class="input-medium search-query">
<button type="submit" class="btn">Search</button>
</form>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span3">
<div class="well">
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-shopping-cart"></i>
3 item - $999.99
<b class="caret"></b></a>
</a>
<div class="dropdown-menu well" role="menu" aria-labelledby="dLabel">
<p>Item x 1 <span class="pull-right">$333.33</span></p>
<p>Item x 1 <span class="pull-right">$333.33</span></p>
<p>Item x 1 <span class="pull-right">$333.33</span></p>
<a href="#" class="btn btn-primary">Checkout</a>
</div>
</div>
</div>
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Sidebar</li>
<li class="active">
<a href="#">Link</a>
</li>
<li>
<a href="#">Link</a>
</li>
<li> <li>
<%= image_tag product.image %> <a href="#">Link</a>
<%= product.name %>
</li> </li>
<li class="nav-header">Sidebar</li>
<li>
<a href="#">Link</a>
</li>
<li>
<a href="#">Link</a>
</li>
<li>
<a href="#">Link</a>
</li>
<li class="nav-header">Sidebar</li>
<li>
<a href="#">Link</a>
</li>
<li>
<a href="#">Link</a>
</li>
<li>
<a href="#">Link</a>
</li>
</ul>
</div>
<div class="well">
<h4>Filters</h4>
<form>
<label class="checkbox">
<input type="checkbox" value="">
Filter 1
</label>
<label class="checkbox">
<input type="checkbox" value="">
Filter 1
</label>
<label class="checkbox">
<input type="checkbox" value="">
Filter 1
</label>
<label class="checkbox">
<input type="checkbox" value="">
Filter 1
</label>
<button class="btn btn-primary pull-right" type="submit">Filter</button>
</form>
</div>
<div class="well">
<h4>Sort</h4>
<form>
<label class="radio">
<input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
Sort 1
</label>
<label class="radio">
<input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
Sort 2
</label>
<button class="btn btn-primary pull-right" type="submit">Sort</button>
</form>
</div>
<div class="well">
<form class="form login-form">
<h2>Sign in</h2>
<div>
<label>Username</label>
<input id="Username" name="Username" type="text" />
<label>Password</label>
<input id="Password" name="Password" type="password" />
<label class="checkbox inline">
<input type="checkbox" id="RememberMe" value="option1"> Remember me
</label>
<br /><br />
<button type="submit" class="btn btn-success">Login</button>
</div>
<br />
<a href="#">register</a>&nbsp;&#124;&nbsp;<a href="#">forgot password?</a>
</form>
</div>
</div>
<div class="span9">
<div class="hero-unit">
<h1 class="">Special Offer</h1>
<p class="">here is the best offer of the month! Do not loose it!</p>
<p><a href="#" class="btn btn-primary btn-large">Learn more »</a></p>
</div>
<ul class="thumbnails">
<li class="span3">
<% @products.each do |product| %>
<div class="thumbnail">
<%= image_tag products.image %>
<div class="caption">
<h4>Thumbnail label</h4>
<p><strike>Euro 150,00</strike>&nbsp;Euro 100,00</p>
<a class="btn btn-primary" href="#">View</a>
<a class="btn btn-success" href="#">Add to Cart</a>
</div>
</div>
<% end %> <% end %>
</ul> </li>
\ No newline at end of file </ul>
<div class="pagination">
<ul>
<li class"disabled"><span>Prev</span></li>
<li class"disabled"><span>1</span></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">Next</a></li>
</ul>
</div>
</div>
</div>
</div>
\ No newline at end of file
...@@ -2,12 +2,9 @@ ...@@ -2,12 +2,9 @@
<div class="navbar-inner"> <div class="navbar-inner">
<div class="container"> <div class="container">
<nav> <nav>
<ul> <%= link_to "About", about_path %>
<li><%= link_to "About", about_path %></li> <%= link_to "Contact", contact_path %>
<li><%= link_to "Contact", contact_path %></li> <a href="http://news.railstutorial.org/">News</a>
<li><a href="http://news.railstutorial.org/">News</a></li>
</ul>
</nav>
</div> </div>
</div> </div>
</footer> </footer>
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
<html> <html>
<head> <head>
<title><!--%= full_title(yield(:title)) %--></title> <title><!--%= full_title(yield(:title)) %--></title>
<!--%= stylesheet_link_tag "application", media: "all" %--> <%= stylesheet_link_tag "application", media: "all" %>
<!--%= javascript_include_tag "application" %--> <%= javascript_include_tag "application" %>
<!--%= csrf_meta_tags %--> <%= csrf_meta_tags %>
<!--%= render 'layouts/shim' %--> <!--%= render 'layouts/shim' %-->
</head> </head>
<body> <body>
......
VenShop::Application.routes.draw do VenShop::Application.routes.draw do
get 'cart_product/new'
get 'cart/new'
devise_for :users devise_for :users
#root to: 'home#index' #root to: 'home#index'
get 'home/index' get 'home/index'
......
...@@ -4,7 +4,7 @@ class CreateProducts < ActiveRecord::Migration ...@@ -4,7 +4,7 @@ class CreateProducts < ActiveRecord::Migration
t.string :name t.string :name
t.string :image t.string :image
t.integer :price t.integer :price
t.string :description t.string :description, limit: 65535
t.integer :category_id t.integer :category_id
t.timestamps null: false t.timestamps null: false
......
...@@ -2,8 +2,6 @@ class CreateCategories < ActiveRecord::Migration ...@@ -2,8 +2,6 @@ class CreateCategories < ActiveRecord::Migration
def change def change
create_table :categories do |t| create_table :categories do |t|
t.string :name t.string :name
t.string :description
t.string :image
t.timestamps null: false t.timestamps null: false
end end
......
class CreateCarts < ActiveRecord::Migration
def change
create_table :carts do |t|
t.integer :User_id
t.integer :total_price
t.string :status
t.string :fullname
t.integer :phone
t.string :address
t.string :email
t.timestamps null: false
end
end
end
class CreateCartProducts < ActiveRecord::Migration
def change
create_table :cart_products do |t|
t.integer :cart_id
t.integer :product_id
t.integer :quantity
t.integer :price
t.timestamps null: false
end
end
end
class AddFieldToUser < ActiveRecord::Migration
def change
add_column :users, :fullname, :string
add_column :users, :phone, :integer
add_column :users, :address, :string
end
end
...@@ -11,12 +11,31 @@ ...@@ -11,12 +11,31 @@
# #
# 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: 20150721071537) do ActiveRecord::Schema.define(version: 20150724084032) do
create_table "cart_products", force: :cascade do |t|
t.integer "cart_id", limit: 4
t.integer "product_id", limit: 4
t.integer "quantity", limit: 4
t.integer "price", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "carts", force: :cascade do |t|
t.integer "User_id", limit: 4
t.integer "total_price", limit: 4
t.string "status", limit: 255
t.string "fullname", limit: 255
t.integer "phone", limit: 4
t.string "address", limit: 255
t.string "email", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "categories", force: :cascade do |t| create_table "categories", force: :cascade do |t|
t.string "name", limit: 255 t.string "name", limit: 255
t.string "description", limit: 65535
t.string "image", limit: 255
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
...@@ -25,7 +44,7 @@ ActiveRecord::Schema.define(version: 20150721071537) do ...@@ -25,7 +44,7 @@ ActiveRecord::Schema.define(version: 20150721071537) do
t.string "name", limit: 255 t.string "name", limit: 255
t.string "image", limit: 255 t.string "image", limit: 255
t.integer "price", limit: 4 t.integer "price", limit: 4
t.string "description", limit: 65535 t.string "description", limit: 20000
t.integer "category_id", limit: 4 t.integer "category_id", limit: 4
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
...@@ -44,6 +63,9 @@ ActiveRecord::Schema.define(version: 20150721071537) do ...@@ -44,6 +63,9 @@ ActiveRecord::Schema.define(version: 20150721071537) do
t.string "last_sign_in_ip", limit: 255 t.string "last_sign_in_ip", limit: 255
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "fullname", limit: 255
t.integer "phone", limit: 4
t.string "address", limit: 255
end end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
......
...@@ -11,14 +11,14 @@ class ImportAmazon ...@@ -11,14 +11,14 @@ class ImportAmazon
end end
def import_product def import_product
(1..10).each do |page| (1..100).each do |page|
get_response(page).each do |item| get_response(page).each do |item|
begin begin
category = Category.find_or_create_by(name: item["ItemAttributes"]["ProductGroup"]) category = Category.find_or_create_by(name: item["ItemAttributes"]["ProductGroup"])
products = Product.find_or_create_by(name: item["ItemAttributes"].to_h["Title"]) do |products| products = Product.find_or_create_by(name: item["ItemAttributes"].to_h["Title"]) do |products|
products.image = item["LargeImage"].to_h["URL"] products.image = item["LargeImage"]["URL"]
products.price = item["ItemAttributes"]["ListPrice"]["Amount"].to_i products.price = item["ItemAttributes"]["ListPrice"]["Amount"].to_i
if item["EditorialReviews"]["EditorialReview"]["Content"] == nil if item["EditorialReviews"]["EditorialReview"]["Content"] != nil
products.description = item["EditorialReviews"]["EditorialReview"]["Content"] products.description = item["EditorialReviews"]["EditorialReview"]["Content"]
else else
products.description = "description" products.description = "description"
......
require 'test_helper'
class CartControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
require 'test_helper'
class CartProductControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
cart_id: 1
product_id: 1
quantity: 1
price: 1
two:
cart_id: 1
product_id: 1
quantity: 1
price: 1
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
User_id: 1
total_price: 1
status: MyString
fullname: MyString
phone: 1
address: MyString
email: MyString
two:
User_id: 1
total_price: 1
status: MyString
fullname: MyString
phone: 1
address: MyString
email: MyString
require 'test_helper'
class CartProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class CartTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
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