Commit 7ab1525a by Dao Minh Nhut

create admin

parent 2a52ca08
......@@ -31,6 +31,8 @@ gem 'will_paginate'
gem 'bootstrap-will_paginate'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
gem 'bcrypt-ruby'
gem 'faker'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
......
......@@ -41,6 +41,8 @@ GEM
execjs
json
bcrypt (3.1.10)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.5.1)
......@@ -70,6 +72,8 @@ GEM
erubis (2.7.0)
excon (0.45.4)
execjs (2.5.2)
faker (1.4.3)
i18n (~> 0.5)
globalid (0.3.5)
activesupport (>= 4.1.0)
i18n (0.7.0)
......@@ -170,11 +174,13 @@ PLATFORMS
ruby
DEPENDENCIES
bcrypt-ruby
bootstrap-sass
bootstrap-will_paginate
byebug
coffee-rails (~> 4.1.0)
devise
faker
jbuilder (~> 2.0)
jquery-rails
mysql2
......@@ -187,6 +193,3 @@ DEPENDENCIES
vacuum
web-console (~> 2.0)
will_paginate
BUNDLED WITH
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/
# 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/
// Place all the styles related to the Cart controller here.
// Place all the styles related to the admins/products 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.
// Place all the styles related to the admins/users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -5582,6 +5582,7 @@ a.thumbnail:focus {
.thumbnail > img {
display: block;
max-width: 100%;
height: 300px;
margin-right: auto;
margin-left: auto;
}
......
// Place all the styles related to the cart_products 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 carts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
@import "bootstrap-sprockets";
@import "bootstrap";
/* mixins, variables, etc. */
$grayMediumLight: #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.7em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: white;
}
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;
line-height: 1;
&:hover {
color: white;
text-decoration: none;
}
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid $grayMediumLight;
color: $grayLight;
a {
color: $gray;
&:hover {
color: $grayDarker;
}
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 10px;
}
}
}
/* sidebar */
aside {
section {
padding: 10px 0;
border-top: 1px solid $grayLighter;
&: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;
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
padding: 10px;
margin-bottom: 15px;
@include box_sizing;
}
input {
height: auto !important;
}
#error_explanation {
color: #f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}
.field_with_errors {
@extend .control-group;
@extend .error;
}
/* users index */
.users {
list-style: none;
margin: 0;
li {
overflow: auto;
padding: 10px 0;
border-top: 1px solid $grayLighter;
&:last-child {
border-bottom: 1px solid $grayLighter;
}
}
}
/* microposts */
.microposts {
list-style: none;
margin: 10px 0 0 0;
li {
padding: 10px 0;
border-top: 1px solid #e8e8e8;
}
}
.content {
display: block;
}
.timestamp {
color: $grayLight;
}
.gravatar {
float: left;
margin-right: 10px;
}
aside {
textarea {
height: 100px;
margin-bottom: 5px;
}
}
/*sidebar*/
@media (min-width: 768px) {
.sb-fixed{
position: fixed;
}
}
\ No newline at end of file
// Place all the styles related to the static_pages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
body {
padding-bottom: 40px;
padding-top: 60px;
}
\ No newline at end of file
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class Admins::CartsController < ApplicationController
def show
@carts = Cart.all
end
def edit
if admin_signed_in? && !params[:cart][:status].nil? && !params[:cart][:status].empty?
@cart = Cart.find(params[:id])
if @cart.status == params[:cart][:status]
flash[:danger] = "Notthing change!"
redirect_to :back
else
@cart.status = params[:cart][:status]
@cart.save
flash[:success] = "Success!"
redirect_to :back
end
else
flash[:danger] = "Notthing change!"
redirect_to action: :index
end
end
end
class Admins::ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation/new
# def new
# super
# end
# POST /resource/confirmation
# def create
# super
# end
# GET /resource/confirmation?confirmation_token=abcdef
# def show
# super
# end
# protected
# The path used after resending confirmation instructions.
# def after_resending_confirmation_instructions_path_for(resource_name)
# super(resource_name)
# end
# The path used after confirmation.
# def after_confirmation_path_for(resource_name, resource)
# super(resource_name, resource)
# end
end
class Admins::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]
# You should also create an action method in this controller like this:
# def twitter
# end
# More info at:
# https://github.com/plataformatec/devise#omniauth
# GET|POST /resource/auth/twitter
# def passthru
# super
# end
# GET|POST /users/auth/twitter/callback
# def failure
# super
# end
# protected
# The path used when OmniAuth fails
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end
end
class Admins::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
end
class Admins::ProductsController < ApplicationController
def insert
@product = Product.new
@categories = Category.all
end
def update
@product = Product.find(params[:id])
@categories = Category.all
end
def create
@categories = Category.all
@product = Product.new(name: params[:product][:name], category_id: params[:product][:category_id].to_i,
price: params[:product][:price].to_i, image: params[:product][:image],
description: params[:product][:description])
if @product.save
flash[:success] = "Create product : Success"
redirect_to admins_product_path(id: "1")
else
flash[:danger] = "Error"
render :insert
end
end
def edit
@categories = Category.all
@product = Product.find(params[:id])
@product.update(product_params)
if @product.save
flash[:success] = "Update product : Success"
redirect_to admins_product_path(id: "1")
else
flash[:danger] = "Error: Price"
render :update
end
end
def delete
@product = Product.find(params[:id])
@product.destroy
redirect_to :back
end
def show
@products = Product.paginate(page: params[:page])
end
def cart
end
def product_params
params.require(:product).permit(:name, :image, :price, :description, :category_id)
end
end
\ No newline at end of file
class Admins::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
# POST /resource
# def create
# super
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.for(:sign_up) << :attribute
# end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.for(:account_update) << :attribute
# end
# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end
# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end
class Admins::SessionsController < Devise::SessionsController
# before_filter :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.for(:sign_in) << :attribute
# end
end
class Admins::UnlocksController < Devise::UnlocksController
# GET /resource/unlock/new
# def new
# super
# end
# POST /resource/unlock
# def create
# super
# end
# GET /resource/unlock?unlock_token=abcdef
# def show
# super
# end
# protected
# The path used after sending unlock password instructions
# def after_sending_unlock_instructions_path_for(resource)
# super(resource)
# end
# The path used after unlocking the resource
# def after_unlock_path_for(resource)
# super(resource)
# end
end
class Admins::UsersController < ApplicationController
def show
@users = User.all
end
end
class ApplicationController < ActionController::Base
protect_from_forgery
#include SessionsHelper
before_action :call_category , only: [:show, :index]
before_action :configure_permitted_parameters, if: :devise_controller?
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include CartsHelper
include CategoriesHelper
# Force signout to prevent CSRF attacks
def handle_unverified_request
sign_out
super
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :username
end
end
class CartController < ApplicationController
def new
end
end
class CartProductController < ApplicationController
def new
end
end
class CartProductsController < ApplicationController
before_action :call_category , only: [:new, :index]
include CategoriesHelper
def add
if params[:id].nil? || params[:quantity].nil?
flash[:danger] = "Product not found!"
redirect_to :action => :index
end
if params[:quantity].to_i > 0
id = params[:id]
if session[:cart] then
cart_product = session[:cart]
else
session[:cart] ={}
cart_product = session[:cart]
end
if cart_product[id] then
cart_product[id] = cart_product[id] + params[:quantity].to_i
else
cart_product[id] = params[:quantity].to_i
end
flash[:success] = "success"
redirect_to :action => :index
end
end
def remove
session[:cart].delete(params[:id].to_s)
redirect_to :action => :index
end
def update
if params[:new_quantity].nil? || params[:id].nil?
flash[:danger] = "Product not found!"
else
session[:cart][params[:id].to_s] = params[:new_quantity].to_i
end
redirect_to :action => :index
end
def clear
session[:cart] = nil
redirect_to :action => :index
end
def index
if session[:cart] then
@cart_product = session[:cart]
else
@cart_product = {}
end
end
end
class CartsController < ApplicationController
include CategoriesHelper
def show
if user_signed_in?
@show_cart = Cart.where(user_id: current_user.id)
end
end
def info
if user_signed_in?
@current_user
end
end
def create
if !session[:cart].nil?
new_cart = Cart.new(cart_params)
new_cart.total_price = calculate_total_price
new_cart.status = "new cart"
if user_signed_in?
new_cart.user_id = current_user.id
end
new_cart.save
if !new_cart.id.nil?
session[:cart].each do |id, quantity|
cart_product = CartProduct.new
cart_product.cart_id = new_cart.id
cart_product.product_id = id
cart_product.price = Product.find_by_id(id).price
cart_product.quantity = quantity
cart_product.save
end
flash[:success] = "Success!"
Emailer.send_email_to(cart_params[:email].to_s,session[:cart]).deliver
session[:cart] = nil
end
end
flash[:danger] = "Wrong input please input again!"
render :info
end
def cart_params
params.require(:session).permit(:fullname, :email, :address, :phone)
end
private
def calculate_total_price
total = 0
if !session[:cart].nil?
session[:cart].each do |id, quantity|
product = Product.find_by_id(id)
if !product.nil?
total = total + product.price * quantity
end
end
end
total
end
end
require 'will_paginate/array'
class CategoriesController < ApplicationController
def new
end
include CategoriesHelper
def show
@items_of_category= Category.find(params[:id]).items
# @items_of_category = Item.all.select do |i|
# i.category_id == params[:id].to_i
# end
@items_of_category=@items_of_category.paginate(:page => params[:page], :per_page => 6)
category = Category.find(params[:id])
@products = category.products
end
end
\ No newline at end of file
class HomeController < ApplicationController
def index
@products = Product.paginate(page: params[:page])
end
end
class ProductsController < ApplicationController
#before_filter :signed_in_user, only: [:create, :destroy]
#before_filter :correct_user, only: :destroy
#def show
#@item = Product.find(params[:id])
#end
include CategoriesHelper
include CartProductsHelper
def index
@item = Product.all
@categories = Category.all
#@items = Product.all.select do |i|
#i.category==params[:id]
#end
@products = Product.paginate(page: params[:page])
end
def new
@item= Product.new
render layout: "another_layout"
end
def create
@item = current_user.items.new(params[:item])
if @item.save
flash[:success] = "Your item has successfully posted!"
redirect_to current_user, layout: "another_layout"
else
render 'new', layout: "another_layout"
def show
begin
@product = Product.find params[:id]
rescue ActiveRecord::RecordNotFound => e
redirect_to carts_path
end
end
def destroy
@item.destroy
redirect_to current_user
end
def correct_user
@item = current_user.items.find_by_id(params[:id])
redirect_to root_url if @item.nil?
end
end
module CartHelper
class StaticPagesController < ApplicationController
end
class Users::ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation/new
# def new
# super
# end
# POST /resource/confirmation
# def create
# super
# end
# GET /resource/confirmation?confirmation_token=abcdef
# def show
# super
# end
# protected
# The path used after resending confirmation instructions.
# def after_resending_confirmation_instructions_path_for(resource_name)
# super(resource_name)
# end
# The path used after confirmation.
# def after_confirmation_path_for(resource_name, resource)
# super(resource_name, resource)
# end
end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]
# You should also create an action method in this controller like this:
# def twitter
# end
# More info at:
# https://github.com/plataformatec/devise#omniauth
# GET|POST /resource/auth/twitter
# def passthru
# super
# end
# GET|POST /users/auth/twitter/callback
# def failure
# super
# end
# protected
# The path used when OmniAuth fails
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end
end
class Users::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
end
class Users::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
# POST /resource
# def create
# super
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.for(:sign_up) << :attribute
# end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.for(:account_update) << :attribute
# end
# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end
# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end
class Users::SessionsController < Devise::SessionsController
# before_filter :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.for(:sign_in) << :attribute
# end
end
class Users::UnlocksController < Devise::UnlocksController
# GET /resource/unlock/new
# def new
# super
# end
# POST /resource/unlock
# def create
# super
# end
# GET /resource/unlock?unlock_token=abcdef
# def show
# super
# end
# protected
# The path used after sending unlock password instructions
# def after_sending_unlock_instructions_path_for(resource)
# super(resource)
# end
# The path used after unlocking the resource
# def after_unlock_path_for(resource)
# super(resource)
# end
end
class UsersController < ApplicationController
include ApplicationHelper
include CartsHelper
include CategoriesHelper
def create
# custom sign-in code
end
end
module CartProductsHelper
end
module CartsHelper
def cart_product
session[:cart] || {}
end
end
module CategoriesHelper
def call_category
@categories = Category.all
end
end
module StaticPagesHelper
end
module UsersHelper
end
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
class Emailer < ApplicationMailer
include ApplicationHelper
include CartsHelper
include CategoriesHelper
def send_email_to(email,cart)
@cart_product = cart
mail to: email, subject: "Venshop!!"
end
end
class ModelMailer < ApplicationMailer
def new_record_notification(record)
@record = record
email to: "recipient@MYDOMAIN.com", subject: "Success! You did it."
end
end
\ No newline at end of file
class UserNotifier < ApplicationMailer
end
class Admin < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
class Cart < ActiveRecord::Base
has_many :cart_product
VALID_PHONE_REGEX = /\d[0-9]\)*\z/
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
VALID_NUMBER_REGEX = /\A[+-]?\d+\Z/
validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }
validates :phone, presence: true, length: { maximum: 15 }, format: { with: VALID_PHONE_REGEX }
validates :total_price, presence: true, format: { with: VALID_NUMBER_REGEX }
validates :fullname, presence: true, length: { maximum: 50 }
validates :address, presence: true, length: { maximum: 1000 }
end
class CartProduct < ActiveRecord::Base
belongs_to :cart
end
class Category < ActiveRecord::Base
has_many :products
has_many :products
def new
@category = Category.new
end
end
class Product < ActiveRecord::Base
# attr_accessible :description, :image, :name, :price
# belongs_to :user
# has_and_belongs_to_many :carts
belongs_to :category
# default_scope order: 'items.created_at DESC'
has_many :cart_products
VALID_NUMBER_REGEX = /\A[+-]?\d+\Z/
validates :category_id, presence: true
validates :name, :image, presence: true, length: { maximum: 1000 }
validates :description, length: { maximum: 65535 }
validates :price, :numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 9999 }
end
<% if admin_signed_in? %>
<div class="span12">
<h2>Products</h2>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Id</th>
<th>Email</th>
<th>Name</th>
<th>Price</th>
<th>Address</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<% @carts.each do |cart|%>
<tr>
<td><%= cart.id.to_s %></td>
<td><%= cart.email.to_s %></td>
<td><%= cart.fullname.to_s %></td>
<td><%= number_to_currency(cart.total_price/100, :unit => "$")%></td>
<td><%= cart.address %></td>
<%= form_for(cart, url: "/admins/carts/#{cart.id}/edit" ) do |f| %>
<td><%= f.text_field :status, value: cart.status.to_s, size: 10 , class: "create_input" %>
</td>
<td>
<%= f.submit "Submit" , class: "btn btn-primary" %>
</td>
<% end %>
</tr>
<% end -%>
</tbody>
</table>
</div>
<% end %>
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>
<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
<h2>Change your password</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div class="field">
<%= f.label :password, "New password" %><br />
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<h2>Forgot your password?</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Send me reset password instructions" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<h2>New products </h2>
<% if @product.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(@product.errors.count, "error") %>.
</div>
<ul>
<% @product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= form_for(@product, url: {action: "create"}) do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
<%= f.label :category_id %>
<%= f.collection_select :category_id, @categories, :id, :name %>
<%= f.label :price %>
<%= f.number_field :price, min: "1", max: "100" %>
<%= f.label :image %>
<%= f.text_field :image %>
<%= f.label :description %>
<%= f.text_area :description, rows: '15' %>
<%= f.submit "New product", class: "btn btn-primary" %>
<% end %>
</div>
<% if admin_signed_in? %>
<div class="span12">
<h2>Products</h2>
<%= link_to "Insert Product", insert_product_path %>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Product Name</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td><%= product.name %></td>
<td><%= link_to "Edit", "/update_product/#{product.id}" %></td>
<td><%= link_to "Delete", "/delete_product/#{product.id}" %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= will_paginate @products%>
<% end %>
<h2>Edit products</h2>
<% if @product.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(@product.errors.count, "error") %>.
</div>
<ul>
<% @product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div>
<%= form_for(@product, url: {action: "edit"}) do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true, class: 'form-control' %>
<%= f.label :category_id %>
<%= f.collection_select :category_id, @categories, :id, :name, :selected => @product.category_id %>
<%= f.label :price %>
<%= f.number_field :price, class: 'form-control' %>
<%= f.label :image %>
<%= f.text_field :image, class: 'form-control' %>
<%= f.label :description %>
<%= f.text_area :description, class: 'form-control', rows: '15' %>
<%= f.submit "Edit", class: "btn btn-primary" %>
<% end %>
</div>
<% if admin_signed_in? %>
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>
<% end %>
\ No newline at end of file
<% if admin_signed_in? %>
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<% end %>
\ No newline at end of file
<h2>Log in</h2>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
<h2>Resend unlock instructions</h2>
<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<% if admin_signed_in? %>
<div class="row">
<h1>All users</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<% @users.each do |user|%>
<tr>
<td><%= user.id.to_s %></td>
<td><%= user.email.to_s %></td>
</tr>
<% end -%>
</tbody>
</table>
</div>
<% end %>
\ No newline at end of file
<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>
<%= render 'categories/view' %>
<div class="span9">
<h2>Shopping Cart</h2>
<div>
<ul>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>Update</th>
<th>Delete</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<% total = 0 %>
<% if !@cart_product.nil? %>
<% @cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% total = total + product.price * quantity.to_i %>
<tr>
<td><%= link_to truncate(product.name, length:20), "/products/#{product.id}" %></td>
<form action="/cart_product/update" >
<td><input name="new_quantity" min="1" max="100" type="number" class="span1" value= <%= quantity %> /></td>
<td><input type="submit" value="Update" /><input type="hidden" name="id" value="<%= product.id %>"/></td>
</form>
<td><form action="/cart_product/remove" ><input type="submit" value="Delete" /><input type="hidden" name="id" value="<%= product.id %>"/></form></td>
<td><%= (product.price/100.to_f).to_s + "$" %></td>
<td><%= ((product.price * quantity)/100.to_f).to_s + "$" %></td>
</tr>
<% end %>
<% end %>
<% else %>
<h2>Shopping Cart Empty</h2>
<% end %>
</tbody>
</table>
</ul>
</div>
<dl class="dl-horizontal pull-right">
<dt>Sub-total:</dt>
<dd><%=(total/100.to_f).to_s + "$" %></dd>
<dt>Total:</dt>
<dd><%=(total/100.to_f).to_s + "$" %></dd>
</dl>
<div class="clearfix"></div>
<%= link_to "Continue Shopping " , root_path, class: "btn btn-primary" %>
<%= link_to "Check Out", "/cart", class: "btn btn-success pull-right"%>&nbsp;&nbsp;
<%= link_to "Delete All" ,'/cart_product/clear', class: "btn btn-lg btn-danger pull-right" %>
<!--%= link_to "info", "/carts", class: "btn btn-lg btn-success"%-->
</div>
\ No newline at end of file
<div class="span12">
<h2>Checkout Process</h2>
<% if !session[:cart].nil? && !session[:cart].empty? %>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<% @total = 0 %>
<% cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% @total = @total + product.price * quantity %>
<tr>
<td><%= link_to truncate(product.name, length:20), "/products/#{product.id}" %></td>
<td><%= quantity %></td>
<td><%= (product.price/100.to_f).to_s + "$" %></td>
<td><%= ((product.price * quantity)/100.to_f).to_s + "$" %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<div>
<dl class="dl-horizontal pull-right">
<dt>Total Price:</dt>
<dd><%= number_to_currency(@total/100.to_f, :unit => '$')%></dd>
</dl></div><br><br><br>
<div align="center">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<div>
<% if user_signed_in? %>
<% email = @current_user.email %>
<% end %>
<%= form_for(:session, url: create_cart_path) do |f| %>
<%= f.label :email %>
<%= f.email_field :email, value: email, class: 'form-control'%>
<%= f.label :fullname %>
<%= f.text_field :fullname, class: 'form-control' %>
<%= f.label :address %>
<%= f.text_field :address, class: 'form-control' %>
<%= f.label :phone %>
<%= f.text_field :phone, class: 'form-control' %>
</br>
<%= f.submit "Submit" , class: "btn btn-primary" %>
<% end %>
</div>
<%else%>
<h1>Your Cart is Empty. Thank you for order</h1>
<% end %>
</div>
</div>
<h1>show cart</h1>
<ul>
<% if !@show_cart.nil? %>
<% @show_cart.each do |cart| %>
<h4>
<%= cart.id.to_s + " | "%>
<%= cart.mail.to_s + " | " %>
<%= cart.name.to_s + " | " %>
<%= cart.total_price.to_s + " | " %>
<%= cart.status.to_s + " | " %>
<%= cart.address %>
</h4>
<% end -%>
<% else -%>
<h2> Your cart Empty </h2>
<% end -%>
</ul>
<div class="span3">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Category</li>
<% @categories.each do |category| %>
<li>
<%= link_to category.name, "/categories/#{category.id}" %>
</li>
<% end %>
</ul>
</div>
</div>
\ No newline at end of file
<h1>Categories#new</h1>
<p>Find me in app/views/categories/new.html.erb</p>
<div class="span9 categories">
<% @items_of_category.each do |i| %>
<div class="span5 center">
<h4><%= i.name%></h4>
<img src= <%= i.image%> atl= "Image not found">
<!-- <p><a class="btn btn-primary" href='/items/<%= i.id %>'>View details »</a></p> -->
<%= button_to "View details", "/items/#{i.id}",
:class => "btn btn-primary", :method => :get %>
</div><!--/span-->
<%end%>
<%= will_paginate @items_of_category, :inner_window => 2%>
</div><!--/span-->
\ No newline at end of file
<%= render 'categories/view' %>
<div class="span9">
<div class="hero-unit">
<h1 class="">Ventura Trainee</h1>
<p class="">Ruby on Rails</p>
<p><%= link_to "Learn more »", about_path, class: "btn btn-primary btn-large"%></p>
</div>
<ul class="thumbnails">
<% @products.each do |product| %>
<li class="span3">
<div class="thumbnail">
<%= image_tag product.image %>
<div class="caption">
<div style="height: 40px">
<h4><%= truncate(product.name, :length => 30, :omission => '...') %></h4>
</div>
<p><%= (product.price/100.to_f).to_s + "$" %></p>
<%= link_to "View Info", "/products/#{product.id}", class: "btn btn-primary" %>
<form action="/cart_products" class="pull-right">
<input type="hidden" name="quantity" value= "1">
<input type="hidden" name="id" value="<%= product.id %>"/>
<input type="submit" value="Add to Cart" class = "btn btn-success" />
</form>
<!--%= link_to "Add to Cart", "/cart_products/#{product.id}", class: "btn btn-success" %-->
</div>
</div>
</li>
<% end %>
</ul>
<div align="center">
</div>
</div>
\ No newline at end of file
<h1>Your Cart</h1>
<ul>
<% total = 0 %>
<% if !@cart_product.nil? %>
<% @cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% total = total + product.price * quantity %>
<li>
<%= product.name %><br>
Price: <%= (product.price/100.to_f).to_s + "$" %><br>
Quantity: <%= quantity %>
</li>
<% end %>
<% end -%>
<% else %>
<h3>Empty</h3>
<% end %>
<br>
<h2>Total: <%= number_to_currency(total/100.to_f, :unit => '$')%> </h2>
</ul>
<div class="navbar navbar-inverse navbar-fixed-top">
<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>
<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>
<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 %>
</li>
</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
<footer class="footer">
<div class="navbar-inner">
<div class="container">
<nav>
<%= link_to "About", about_path %>
<%= link_to "Contact", contact_path %>
<a href="http://news.railstutorial.org/">News</a>
<footer id="footer" class="vspace20">
<div class="container">
<div class="row">
<div class="span6">
<p>VenShop Ruby on Rails</p>
</div>
<div class="span6">
<nav class="pull-right">
<%= link_to "FAQs", faqs_path %>
<%= link_to "Help", help_path %>
</nav>
</div>
</div>
</div>
</footer>
</footer>
\ No newline at end of file
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<!--%= link_to "VenShop", root_path, id: "logo" %-->
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", users_path %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="/">VenShop</a>
<div class="nav-collapse collapse">
<!--%= link_to "VenShop", root_path, id: "logo" %-->
<ul class="nav">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "About", about_path %></li>
<li><%= link_to "Contact", contact_path %></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-->
<ul class="nav pull-right">
<% if user_signed_in? %>
<!--li><%= link_to "Carts", "" %></li-->
<!--li><%= link_to "Profile", "" %></li-->
<li><%= link_to "Settings", edit_user_registration_path %></li>
<li><%= link_to "Log out", destroy_user_session_path, method: "delete" %></li>
<% elsif admin_signed_in? %>
<li><%= link_to "Products", admins_product_path(id: "1") %></li>
<li><%= link_to "Carts", show_cart_path %></li>
<li><%= link_to "Users", show_user_path %></li>
<li><%= link_to "Sign Out", destroy_admin_session_path, method: "delete" %></li>
<% else %>
<li><%= link_to "Carts", carts_path %></li>
<li><%= link_to "Sign In", new_user_session_path %></li>
<li><%= link_to "Sign Up", new_user_registration_path%></li>
<% end %>
</ul>
</div>
</div>
</div>
</div>
</header>
\ No newline at end of file
<div class="span3">
<div class="sidebar-nav-fixed">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Category</li>
<!--% category_list.each do |cat| %-->
<li><a href='/categories/<%= cat.id%>'><%=cat.name%></a></li>
<!--%end%-->
</ul>
</div><!--/.well -->
</div> <!--/sidebar-nav-fixed -->
</div><!--/span-->
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<!-- <%= debug(params) if Rails.env.development? %> -->
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title><!--%= full_title(yield(:title)) %--></title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<title>VenShop</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<!--%= render 'layouts/shim' %-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Included Bootstrap CSS Files -->
<link rel="stylesheet" href="./js/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="./js/bootstrap/css/bootstrap-responsive.min.css" />
<!-- Includes FontAwesome -->
<link rel="stylesheet" href="./css/font-awesome/css/font-awesome.min.css" />
<!-- Css -->
<link rel="stylesheet" href="./css/style.css" />
</head>
<body>
<!--%= render 'layouts/header' %-->
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
<div class="span12 span-fixed-sidebar">
<div class="center hero-unit">
<h1 style="color:blue">Welcome to VenShop</h1>
<% if !signed_in? %>
<!--%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %-->
<% end %>
</div>
<%= render 'layouts/search' %>
<% if signed_in? %>
<div class= "span3">
<%= button_to "My cart", '/user/cart/',
:class => "btn btn-primary", :method => :get %>
</div>
<% end %>
<div style= "clear: both"></div>
<div class="row-fluid">
<!--%= render 'layouts/sidebar' %-->
<%= yield %>
</div>
<div class="row">
<%= yield %>
</div>
</div>
<hr />
<%= render 'layouts/footer' %>
<!-- <%= debug(params) if Rails.env.development? %> -->
</body>
</html>
\ No newline at end of file
<html>
<body>
<%= yield %>
</body>
</html>
<li class = "center">
<span class="content"><%= item.name %></span>
<img src= <%= item.image%> atl= "Image not found" width="250" height="250"><br>
<p><a class="btn" href='/items/<%= item.id %>'>View details »</a></p>
<span class="timestamp">
Posted <%= time_ago_in_words(item.created_at) %> ago.
</span>
<% if current_user?(item.user) %>
<%= link_to "delete", item, method: :delete,
data: { confirm: "Are you sure?" },
title: item.name %>
<% end %>
</li>
\ No newline at end of file
<%= render 'categories/view' %>
<div class="span9">
<div class="hero-unit">
<h1 class="">Ventura Trainee</h1>
<p class="">Ruby on Rails</p>
<p><%= link_to "Learn more »", about_path, class: "btn btn-primary btn-large"%></p>
</div>
<ul class="thumbnails">
<% @products.each do |product| %>
<li class="span3">
<div class="thumbnail">
<%= image_tag product.image %>
<div class="caption">
<div style="height: 40px">
<h4><%= truncate(product.name, :length => 30, :omission => '...') %></h4>
</div>
<p><%= (product.price/100.to_f).to_s + "$" %></p>
<%= link_to "View Info", "/products/#{product.id}", class: "btn btn-primary" %>
<form action="/cart_products" class="pull-right" >
<input type="hidden" name="quantity" value= "1">
<input type="hidden" name="id" value="<%= product.id %>"/>
<input type="submit" value="Add to Cart" class = "btn btn-success" />
</form>
<!--%= link_to "Add to Cart", "/cart_products/#{product.id}", class: "btn btn-success" %-->
</div>
</div>
</li>
<% end %>
</ul>
<div align="center">
<%= will_paginate @products%>
</div>
</div>
\ No newline at end of file
<div class="container-home">
<div class="items">
<div class="clear" />
<div class="newest">
<div class="headline-newest">Add new product</div>
<div class="list-Browse-NewsRv">
<div class="span6 offset3" style="margin-left:0px">
<%= form_for(@product) do |f| %>
<%= f.label :Title %>
<%= f.text_field :title %>
<%= f.label :Price %>
<%= f.text_field :price %>
<%= f.label :Image %>
<%= f.text_field :img %>
<%= f.label :Category %>
<%= f.collection_select(:categoryid, Category.all, :id, :name) %>
<%= f.submit "Add new", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
</div>
</div></div>
\ No newline at end of file
<div class="span8 center">
<h3>Name: </h3><%= @product.name%><br><br>
</div><!--/span-->
\ No newline at end of file
<%= render 'categories/view' %>
<div class="span9">
<div class="row">
<div class="span5">
<div id="items-carousel" class="carousel slide mbottom0">
<div class="carousel-inner">
<div class="active item">
<%= image_tag @product.image %>
</div>
</div>
</div>
</div>
<div class="span4">
<h4><%= @product.name %></h4>
<p><%= (@product.price/100.to_f).to_s + " $" %></p>
<label>Quantity:</label>
<div>
<form action="/cart_products">
<input type="number" name="quantity" value= "1" min="1" max="100" value="1">
<input type="hidden" name="id" value="<%= @product.id %>"/>
<input type="submit" value="Add to cart" class = "btn btn-lg btn-success" />
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span9">
<div class="tab-content">
<div class="tab-pane active" id="description">
<p><%= simple_format(@product.description) %></p>
</div>
</div>
</div>
</div>
\ No newline at end of file
<% if @product.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(@product.errors.count, "error") %>.
</div>
<ul>
<% @product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
\ No newline at end of file
<div class="span3 sb-fixed">
<div class="well sidebar-nav">
<!-- Sidebar Contents -->
<% @category_list.each do |cat|%>
<%=link_to "#{cat.name}", signup_path,
class: "btn btn-large btn-primary" %>
<h1>hello</h1>
<% end %>
</div>
</div>
<% provide(:title, 'Contact') %>
<h1>FAQs</h1>
<p>
<h1>Nothings to post here!</h1>
</p>
\ No newline at end of file
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>
<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
<h2>Change your password</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div class="field">
<%= f.label :password, "New password" %><br />
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>
<%= render "users/shared/links" %>
<h2>Forgot your password?</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Send me reset password instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "users/shared/links" %>
<h2>Log in</h2>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= render "users/shared/links" %>
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
<h2>Resend unlock instructions</h2>
<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>
......@@ -12,7 +12,22 @@ VenShop::Application.configure do
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
host = 'localhost:3000'
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# # host = 'loc'
# Actionmailer::Base.delivery_method = :smtp
# Actionmailer::Base.smtp_settings = {
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "localhost:3000",
authentication: "plain",
enable_starttls_auto: true,
user_name: "daominhnhut2602@gmail.com",
password: "nhut123456789"
}
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
......
VenShop::Application.routes.draw do
get 'cart_product/new'
namespace :admins do
get 'users/show'
end
get 'cart/new'
namespace :admins do
get 'users/new'
end
devise_for :users
#root to: 'home#index'
get 'home/index'
get 'categories/new'
get 'products/show'
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
# match '/categories/:id', to: 'categories#show'
# match '/items/:id', to: 'items#show'
devise_for :admins
namespace :admins do
resources :products
end
root 'products#index'
get 'show_product' => 'products#index'
get 'insert_product' => 'admins/products#insert'
get 'update_product/:id' => 'admins/products#update'
get 'delete_product/:id' => 'admins/products#delete'
get 'show_cart' => 'admins/carts#show'
get 'show_user' => 'admins/users#show'
patch '/admins/products/:id/edit'=>'admins/products#edit'
patch '/admins/carts/:id/edit' => 'admins/carts#edit'
get 'cart_products' => 'cart_products#add'
get 'cart_product/remove' => 'cart_products#remove'
get 'cart_product/update' => 'cart_products#update'
get 'cart_product/clear' => 'cart_products#clear'
get 'cart' => 'carts#info'
get 'carts' => 'cart_products#index'
get 'carts/show' => 'carts#show'
post 'carts/create' => 'carts#create', as: 'create_cart'
get '/product' => 'products#show'
get '/help' => 'static_pages#help'
get '/about' => 'static_pages#about'
get '/contact' => 'static_pages#contact'
get '/faqs' => 'static_pages#faqs'
get 'products/:id' => 'products#show'
get 'category/:id' => 'category#show'
resources :categories, only: [:index, :show]
resources :products, only: [:index, :show]
resources :carts, only: [:info,:destroy]
resources :cart_products, only: [:new, :edit, :update, :index]
# match '/categories/:id', to: 'categories#show'
# match '/items/:id', to: 'items#show'
# match '/user/add_to_cart/:id', to: 'users#add_to_cart'
# match 'user/check_out/', to: 'users#check_out'
# match '/user/cart', to: 'users#cart'
......
class DeviseCreateAdmins < ActiveRecord::Migration
def change
create_table(:admins) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :admins, :email, unique: true
add_index :admins, :reset_password_token, unique: true
# add_index :admins, :confirmation_token, unique: true
# add_index :admins, :unlock_token, unique: true
end
end
......@@ -11,7 +11,25 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150724084032) do
ActiveRecord::Schema.define(version: 20150730075349) do
create_table "admins", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", limit: 4, default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "admins", ["email"], name: "index_admins_on_email", unique: true, using: :btree
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true, using: :btree
create_table "cart_products", force: :cascade do |t|
t.integer "cart_id", limit: 4
......
require 'test_helper'
class Admins::ProductsControllerTest < ActionController::TestCase
test "should get insert" do
get :insert
assert_response :success
end
test "should get update" do
get :update
assert_response :success
end
test "should get product" do
get :product
assert_response :success
end
test "should get cart" do
get :cart
assert_response :success
end
end
require 'test_helper'
class CartControllerTest < ActionController::TestCase
test "should get new" do
get :new
class Admins::UsersControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end
......
require 'test_helper'
class CartProductControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
require 'test_helper'
class CartProductsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class CartsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
# Preview all emails at http://localhost:3000/rails/mailers/user_notifier
class UserNotifierPreview < ActionMailer::Preview
end
require 'test_helper'
class UserNotifierTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class AdminTest < 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