Commit 8714b293 by Vy Quoc Vu

search

parent 70904e91
# 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 admins/carts 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 admins/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 index
if admin_signed_in?
@carts = Cart.all
end
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
...@@ -3,13 +3,14 @@ class Admins::ProductsController < ApplicationController ...@@ -3,13 +3,14 @@ class Admins::ProductsController < ApplicationController
@product = Product.new @product = Product.new
end end
def create def create
if admin_signed_in? if admin_signed_in?
if product_params[:price].to_i >= 0 && product_params[:category_id].to_i > 0 && !product_params[:image].nil? if product_params[:price].to_i >= 0 && params[:category][:id].to_i > 0 && !product_params[:image].nil? && !product_params[:image].empty? && !product_params[:price].empty? && !product_params[:name].empty? && product_params[:price].to_i <= 999999
product = Product.find_or_create_by(name: product_params[:name]) do |product| product = Product.find_or_create_by(name: product_params[:name]) do |product|
product.image = product_params[:image] product.image = product_params[:image]
product.category_id = product_params[:category_id] product.category_id = params[:category][:id]
product.price = product_params[:price] product.price = product_params[:price].to_i*100
product.description = product_params[:description] product.description = product_params[:description]
end end
flash[:success] = "Success!" flash[:success] = "Success!"
...@@ -23,16 +24,15 @@ class Admins::ProductsController < ApplicationController ...@@ -23,16 +24,15 @@ class Admins::ProductsController < ApplicationController
def edit def edit
if admin_signed_in? if admin_signed_in?
if product_params[:price].to_i >= 0 && product_params[:category_id].to_i > 0 && !product_params[:image].nil? if product_params[:price].to_i >= 0 && params[:category][:id].to_i > 0 && !product_params[:image].nil? && !product_params[:image].empty? && !product_params[:price].empty? && !product_params[:name].empty? && product_params[:price].to_i <= 999999
product = Product.find(params[:id]) product = Product.find(params[:id])
byebug
product.name = product_params[:name] product.name = product_params[:name]
product.image = product_params[:image] product.image = product_params[:image]
product.category_id = product_params[:category_id] product.category_id = params[:category][:id]
product.price = product_params[:price] product.price = product_params[:price].to_i*100
product.description = product_params[:description] product.description = product_params[:description]
product.save product.save
byebug
flash[:success] = "Success!" flash[:success] = "Success!"
redirect_to "/products/#{product.id}" redirect_to "/products/#{product.id}"
else else
...@@ -57,14 +57,13 @@ class Admins::ProductsController < ApplicationController ...@@ -57,14 +57,13 @@ class Admins::ProductsController < ApplicationController
else else
flash[:danger] = "Only Admin" flash[:danger] = "Only Admin"
end end
end end
private private
def product_params def product_params
params.require(:product).permit(:name, :price, :description, params.require(:product).permit(:name, :price, :description,
:image, :category_id, :id) :image, :id)
end end
end end
\ No newline at end of file
class Admins::UsersController < ApplicationController
def index
if admin_signed_in?
@users = User.all
end
end
end
class ProductsController < ApplicationController class ProductsController < ApplicationController
include ApplicationHelper
include CategoriesHelper include CategoriesHelper
def index def index
@products = Product.paginate(page: params[:page], :per_page => 50) @products = Product.paginate(page: params[:page], :per_page => 50)
@search_products = Product.new
end end
def show def show
@product = Product.find(params[:id]) if !Product.find(params[:id]).nil?
@product = Product.find(params[:id])
else
flash[:danger] = "Product not found!"
end
end end
def add def search
if params[:product][:search]
@products = Product.search(params[:product][:search]).paginate(page: params[:page], :per_page => 50)
flash[:success] = "Success!"
else
flash[:danger] = "Danger!"
end
end end
end end
module Admins::CartsHelper
end
module Admins::UsersHelper
end
...@@ -3,4 +3,8 @@ class Admin < ActiveRecord::Base ...@@ -3,4 +3,8 @@ class Admin < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
end end
...@@ -4,5 +4,4 @@ class Cart < ActiveRecord::Base ...@@ -4,5 +4,4 @@ class Cart < ActiveRecord::Base
validates :mail, presence: true, length: { maximum: 255 }, validates :mail, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX } format: { with: VALID_EMAIL_REGEX }
belongs_to :user belongs_to :user
has_many :cart_product
end end
class CartProduct < ActiveRecord::Base class CartProduct < ActiveRecord::Base
belongs_to :cart validates :name, presence: true, length: { maximum: 255 }
validates :price, presence: true, length: {maximum: 4}
end end
class Category < ActiveRecord::Base class Category < ActiveRecord::Base
has_many :products has_many :products
validates :name, presence: true, length: { maximum: 255 }
def new def new
@category = Category.new @category = Category.new
end end
# def create
# @category = Category.new
# end
end end
class Product < ActiveRecord::Base class Product < ActiveRecord::Base
belongs_to :category belongs_to :category
validates :name, presence: true, length: { maximum: 3000 }
validates :image, presence: true, length: { maximum: 1000 }
validates :description, presence: true, length: { maximum: 65000 }
def self.search(search)
if search
Product.where('name LIKE ?', "%#{search}%")
end
end
end end
...@@ -4,4 +4,8 @@ class User < ActiveRecord::Base ...@@ -4,4 +4,8 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
end end
<% if admin_signed_in? %>
<div class="row">
<table class="table">
<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.mail.to_s %></td>
<td><%= cart.name.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 %>
<% if admin_signed_in? %> <% if admin_signed_in? %>
<h1>Add Products</h1> <h1>Add product</h1>
<div class="row"> <%= form_for(@product, url: {action: "create"}) do |f| %>
<div class="col-md-3" style=" padding-top: 50px;"> <%= f.label :name %>
<% if admin_signed_in? %> <%= f.text_field :name, value: "", class: 'form-control'%>
<h1>Admin</h1>
<%= render 'layouts/admin' %>
<% end %>
</div>
<div class="col-md-9" style=" padding-top: 50px;">
<%= form_for(@product, url: {action: "create"}) do |f| %>
<%= f.label :name %>
<%= f.text_field :name, value: "", class: 'form-control'%>
<%= f.label :price %> <%= f.label :price %>
<%= f.number_field :price, value: "", class: 'form-control' %> <%= f.number_field :price, value: "", class: 'form-control' %>
<%= f.label :Category %>
<%= collection_select :category, :id, Category.all, :id, :name %>
</br>
<%= f.label :description %>
<%= f.text_area :description, class: 'form-control' %>
<%= f.label :category_id %> <%= f.label :image %>
<%= f.number_field :category_id, value: "", class: 'form-control' %> <%= f.text_field :image, class: 'form-control' %>
</br>
<%= f.label :description %> <%= f.submit "Submit" , class: "btn btn-primary" %>
<%= f.text_area :description, class: 'form-control' %> <% end %>
<%= f.label :image %>
<%= f.text_field :image, class: 'form-control' %>
</br>
<%= f.submit "Submit" , class: "btn btn-primary" %>
<% end %>
</div>
</div>
<% else %> <% else %>
<h1>Only Admin</h1> <h1>Only Admin</h1>
<% end %> <% end %>
\ No newline at end of file
<% if admin_signed_in? %> <% if admin_signed_in? %>
<div class="col-md-3" style=" padding-top: 50px;"> <div class="row">
<% if admin_signed_in? %> <h1>Update product</h1>
<h1>Admin</h1> <div class="center jumbotron" >
<%= render 'layouts/admin' %> <%= image_tag(@product.image)%>
<% end %> </div>
</div> <%= form_for(@product, url: {action: "edit"}) do |f| %>
<div class="col-md-9" style=" padding-top: 50px;"> <%= f.label :name %>
<div class="center jumbotron"> <%= f.text_field :name, value: @product.name, class: 'form-control'%>
<%= image_tag(@product.image)%>
<h3><%= (@product.price/100.to_f).to_s + "$" %></h3>
<%= form_for(@product, url: {action: "edit"}) do |f| %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control'%>
<%= f.label :price %>
<%= f.number_field :price, class: 'form-control' %>
<%= f.label :category_id %> <%= f.label :price %>
<%= f.number_field :category_id, class: 'form-control' %> <%= f.number_field :price, value: @product.price/100, class: 'form-control' %>
<br>
<%= f.label :Category %>
<%= collection_select :category, :id, Category.all, :id, :name, :selected => @product.category_id %>
</br>
<%= f.label :description %> <%= f.label :description %>
<%= f.text_area :description, class: 'form-control' %> <%= f.text_area :description, value: @product.description, class: 'form-control' %>
<%= f.label :image %> <%= f.label :image %>
<%= f.text_field :image, class: 'form-control' %> <%= f.text_field :image, value: @product.image, class: 'form-control' %>
</br> </br>
<%= f.submit "Submit" , class: "btn btn-primary" %> <%= f.submit "Submit" , class: "btn btn-primary" %>
<% end %> <% end %>
</div>
</div> </div>
<% else %> <% else %>
<h1>Only Admin</h1> <h1>Only Admin</h1>
......
<h2>Log in Admin</h2> <h2>Log in Admin</h2>
<div class="col-md-12">
<div class="center jumbotron">
<%= 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>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> <div class="field">
<div class="field"> <%= f.label :password %><br />
<%= f.label :email %><br /> <%= f.password_field :password, autocomplete: "off" %>
<%= f.email_field :email, autofocus: true %> </div>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<% if devise_mapping.rememberable? -%> <% if devise_mapping.rememberable? -%>
<div class="field"> <div class="field">
<%= f.check_box :remember_me %> <%= f.check_box :remember_me %>
<%= f.label :remember_me %> <%= f.label :remember_me %>
</div> </div>
<% end -%> <% end -%>
<div class="actions"> <div class="actions">
<%= f.submit "Log in" %> <%= f.submit "Log in" %>
</div>
<% end %>
</div> </div>
<% end %> </div>
<%= render "admins/shared/links" %> <%= 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 %>
<h1>Your Cart</h1> <h1>Your Cart</h1>
<div class="col-md-3" style=" padding-top: 50px;"> <div class="col-md-3">
<% if admin_signed_in? %> <% if !admin_signed_in? %>
<h1>Admin</h1>
<%= render 'layouts/admin' %>
<% else %>
<%= render 'layouts/cart' %> <%= render 'layouts/cart' %>
<%= render 'categories/view' %> <%= render 'categories/view' %>
<% end %> <% end %>
</div> </div>
<div class="col-md-9" style=" padding-top: 50px;"> <div class="col-md-9">
<div class="col-md-12"> <div class="col-md-12">
<form class="navbar-left" style="padding-left: 0px" > <form class="navbar-left" style="padding-left: 0px" >
<%= link_to "Empty Cart" ,'/cart_product/clear' %> <%= link_to "Empty Cart" ,'/cart_product/clear' %>
...@@ -48,8 +45,6 @@ ...@@ -48,8 +45,6 @@
<% end -%> <% end -%>
</ul> </ul>
</div> </div>
<div class="footer col-md-12"> <div class="footer col-md-12">
</br> </br>
</br> </br>
......
<% if !session[:cart].nil? && !session[:cart].empty? %> <% if !session[:cart].nil? && !session[:cart].empty? %>
<div class="col-md-3" style=" padding-top: 50px;"> <div class="col-md-3" style=" padding-top: 50px;">
<% if admin_signed_in? %> <% if !admin_signed_in? %>
<h1>Admin</h1>
<%= render 'layouts/admin' %>
<% else %>
<%= render 'layouts/cart' %> <%= render 'layouts/cart' %>
<% end %> <% end %>
</div> </div>
......
<h1>show cart</h1> <h1>Show cart</h1>
<div class="col-md-3" style=" padding-top: 50px;"> <div class="col-md-3" style=" padding-top: 50px;">
<% if admin_signed_in? %> <% if !admin_signed_in? %>
<h1>Admin</h1>
<%= render 'layouts/admin' %>
<% else %>
<%= render 'layouts/cart' %> <%= render 'layouts/cart' %>
<%= render 'categories/view' %>
<% end %> <% end %>
</div> </div>
<div class="col-md-9" style=" padding-top: 50px;"> <div class="col-md-9" style=" padding-top: 50px;">
<ul> <ul>
<% if !@show_cart.nil? %> <% if !@show_cart.nil? %>
<% @show_cart.each do |cart| %> <table class="table">
<h4> <thead>
<%= cart.id.to_s + " | "%> <tr>
<%= cart.mail.to_s + " | " %> <th>Id</th>
<%= cart.name.to_s + " | " %> <th>Email</th>
<%= cart.total_price.to_s + " | " %> <th>Name</th>
<%= cart.address+ " | " %> <th>Price</th>
<%= cart.status.to_s %> <th>Address</th>
</h4> <th>Status</th>
<% end -%> <th></th>
</tr>
</thead>
<tbody>
<% @show_cart.each do |cart|%>
<tr>
<td><%= cart.id.to_s %></td>
<td><%= cart.mail.to_s %></td>
<td><%= cart.name.to_s %></td>
<td><%= number_to_currency(cart.total_price/100, :unit => "$")%></td>
<td><%= cart.address %></td>
<td><%= cart.status.to_s %></td>
</tr>
<% end -%>
</tbody>
</table>
<% else -%> <% else -%>
<h2> Your cart Empty </h2> <h2> Your cart Empty </h2>
<% end -%> <% end -%>
......
<div class="col-md-3" style=" padding-top: 50px;"> <div class="col-md-3" >
<% if admin_signed_in? %> <% if !admin_signed_in? %>
<h1>Admin</h1>
<%= render 'layouts/admin' %>
<% else %>
<%= render 'layouts/cart' %> <%= render 'layouts/cart' %>
<%= render 'categories/view' %>
<% end %> <% end %>
<%= render 'categories/view' %>
</div> </div>
<div class="col-md-9" style=" padding-top: 50px;"> <div class="col-md-9">
<% @products.each do |product| %> <% @products.each do |product| %>
<div class="col-md-4"> <div class="col-md-4">
<div class="center jumbotron" style="padding-left : 40px;"> <div style="padding-left : 20px;">
<%= image_tag(product.image, size: "170x210")%> <%= image_tag(product.image, size: "180x230")%>
<h5><%= truncate(product.name, length: 22) %></h5> <h5><%= truncate(product.name, length: 22) %></h5>
<%= (product.price/100.to_f).to_s + "$" %> <%= (product.price/100.to_f).to_s + "$" %>
</br> </br>
<%= link_to "Info", "/products/#{product.id}", class: "btn btn-lg btn-info" %> <% if admin_signed_in? %>
<%= link_to "Buy", "/products/#{product.id}", class: "btn btn-lg btn-danger" %> <%= link_to "Edit", "/admins/products/#{product.id}", class: "btn btn-lg btn-primary" %>
<%= link_to "delete", "/admins/destroy/#{product.id}", class: "btn btn-lg btn-danger" %>
<%else %>
<%= link_to "Info", "/products/#{product.id}", class: "btn btn-lg btn-info" %>
<%= link_to "Buy", "/products/#{product.id}", class: "btn btn-lg btn-danger" %>
<%end %>
</div> </div>
</div> </div>
<% end -%> <% end -%>
......
<h2>Edit <%= resource_name.to_s.humanize %></h2> <h2>Edit <%= resource_name.to_s.humanize %></h2>
<div class="col-md-12">
<div class="center jumbotron">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %> <%= devise_error_messages! %>
...@@ -37,3 +38,5 @@ ...@@ -37,3 +38,5 @@
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p> <p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %> <%= link_to "Back", :back %>
</div>
</div>
<h2>Sign up Devise</h2> <h2>Sign up Devise</h2>
<div class="col-md-12">
<div class="center jumbotron">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <div class="field">
<%= devise_error_messages! %> <%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field"> <div class="field">
<%= f.label :email %><br /> <%= f.label :password %>
<%= f.email_field :email, autofocus: true %> <% if @minimum_password_length %>
</div> <em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field"> <div class="field">
<%= f.label :password %> <%= f.label :password_confirmation %><br />
<% if @minimum_password_length %> <%= f.password_field :password_confirmation, autocomplete: "off" %>
<em>(<%= @minimum_password_length %> characters minimum)</em> </div>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field"> <div class="actions">
<%= f.label :password_confirmation %><br /> <%= f.submit "Sign up" %>
<%= f.password_field :password_confirmation, autocomplete: "off" %> </div>
<% end %>
</div> </div>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "devise/shared/links" %> <%= render "devise/shared/links" %>
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
<h1>Your Cart</h1> <h1>Your Cart</h1>
<ul> <ul>
<% total = 0 %> <% total = 0 %>
<%byebug%>
<% if !@cart_product.nil? %> <% if !@cart_product.nil? %>
<% @cart_product.each do |id, quantity| %> <% @cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %> <% product = Product.find_by_id(id) %>
......
<h3>Home</h3> <div id="sidebar-wrapper" style = "padding-top: 0px;">
<h3>Categories</h3> <ul class="sidebar-nav">
<h3>Products</h3> <li class="sidebar-brand">
<h3>Cart</h3> <h3><%=link_to("Home", root_path )%></h3>
\ No newline at end of file </li>
<li>
<h3><%=link_to("Products", new_admins_product_path )%></h3>
</li>
<li>
<h3><%=link_to("Carts", '/admins/carts' )%></h3>
</li>
<li>
<h3><%=link_to("Users", '/admins/users' )%></h3>
</li>
</ul>
</div>
\ No newline at end of file
...@@ -4,19 +4,11 @@ ...@@ -4,19 +4,11 @@
<div class="container-fluid"> <div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display --> <!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href= "/index" > Venshop </a> <a class="navbar-brand" href= "/" > Venshop </a>
</div> </div>
<!-- Collect the nav links, forms, and other content for toggling --> <!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="collapse"> <div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav">
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search" style="width: 300px;">
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<% if user_signed_in? || admin_signed_in? %> <% if user_signed_in? || admin_signed_in? %>
<li> <li>
......
...@@ -8,9 +8,17 @@ ...@@ -8,9 +8,17 @@
<%= render 'layouts/shim' %> <%= render 'layouts/shim' %>
</head> </head>
<body> <body>
<% if admin_signed_in? %>
<%= render 'layouts/admin' %>
<% end %>
<div class="container"> <div class="container">
<%= render 'layouts/header' %> <%= render 'layouts/header' %>
<%= yield %> <div class="container" class="col-md-12">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
</div>
<%= yield %>
</div> </div>
<%= render 'layouts/footer' %> <%= render 'layouts/footer' %>
</body> </body>
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
<%= simple_format(truncate(product.name, length:21)) %> <%= simple_format(truncate(product.name, length:21)) %>
</div> </div>
<div> <div>
<% price = (product.price/100.to_f) %> <p> Price: <%= price = (product.price/100.to_f) %> </p>
<input type="number" name="quantity" min="1" max="100" value=<%= price %> >
</br> </br>
<%= link_to "Edit", "/admins/products/#{product.id}", class: "btn btn-lg btn-primary" %> <%= link_to "Edit", "/admins/products/#{product.id}", class: "btn btn-lg btn-primary" %>
<%= link_to "delete", "/admins/destroy/#{product.id}", class: "btn btn-lg btn-danger" %> <%= link_to "delete", "/admins/destroy/#{product.id}", class: "btn btn-lg btn-danger" %>
......
<div class="row"> <div class="row">
<div class="col-md-3" style=" padding-top: 50px;"> <div class="col-md-3">
<% if admin_signed_in? %> <% if !admin_signed_in? %>
<%= render 'layouts/admin' %>
<% else %>
<%= render 'layouts/cart' %> <%= render 'layouts/cart' %>
<%= render 'categories/view' %>
<% end %> <% end %>
<%= render 'categories/view' %>
</div> </div>
<div class="col-md-9" style=" padding-top: 50px;"> <div class="col-md-9" >
<% flash.each do |message_type, message| %> <div class="form-group">
<div class="alert alert-<%= message_type %>"><%= message %></div> <table class="table">
<% end %> <tr>
<%= form_for(@search_products, url: "search", method: :get) do |f| %>
<th class="col-md-6">
<%= f.text_field :search, value: "" ,class: 'form-control' %>
</th>
<th>
<%= f.submit "Search" , class: "btn btn-primary" %>
</th>
<% end %>
</tr>
</table>
</div>
<% if admin_signed_in? %> <% if admin_signed_in? %>
<%= render 'products/admin_products' %> <%= render 'products/admin_products' %>
<% else %> <% else %>
<%= render 'products/custom_products' %> <%= render 'products/custom_products' %>
<% end %> <% end %>
</div> </div>
</div> </div>
\ No newline at end of file
<div class="row">
<div class="col-md-3">
<% if !admin_signed_in? %>
<%= render 'layouts/cart' %>
<% end %>
</div>
<div class="col-md-9" >
<% if admin_signed_in? %>
<%= render 'products/admin_products' %>
<% else %>
<%= render 'products/custom_products' %>
<% end %>
</div>
</div>
\ No newline at end of file
<div class="col-md-3" style=" padding-top: 50px;"> <% if !admin_signed_in? %>
<% if admin_signed_in? %> <div class="col-md-3">
<h1>Admin</h1> <%= render 'layouts/cart' %>
<% else %> <%= render 'categories/view' %>
<%= render 'layouts/cart' %> </div>
<%= render 'categories/view' %> <div class="col-md-9">
<% end %> <% end %>
</div> <div class="center jumbotron">
<div class="col-md-9" style=" padding-top: 50px;">
<div class="center jumbotron" style="padding-left: 35px;">
<%= image_tag(@product.image)%> <%= image_tag(@product.image)%>
<h3><%= simple_format(@product.name) %></h3> <h3><%= simple_format(@product.name) %></h3>
<h3><%= (@product.price/100.to_f).to_s + "$" %></h3> <h3><%= (@product.price/100.to_f).to_s + "$" %></h3>
</br> </br>
<%= simple_format(@product.description) %> <%= simple_format(@product.description) %>
</br> </br>
<% if admin_signed_in? %>
<form action="/cart_products" style="padding-left: 0px" > <%= link_to "Edit", "/admins/products/#{@product.id}", class: "btn btn-lg btn-success" %>
<input type="number" name="quantity" value= "1" min="1" max="100" value="1"> <% else%>
</br> <form action="/cart_products" style="padding-left: 0px" >
<input type="submit" value="Add" class = "btn btn-lg btn-success" /> <input type="number" name="quantity" value= "1" min="1" max="100" value="1">
<input type="hidden" name="id" value="<%= @product.id %>"/> </br>
</form> <input type="submit" value="Add" class = "btn btn-lg btn-success" />
<input type="hidden" name="id" value="<%= @product.id %>"/>
</form>
<% end %>
</div> </div>
</div> </div>
\ No newline at end of file
<h2>Log in user</h2> <h2>Log in user</h2>
<div class="col-md-12">
<div class="center jumbotron">
<%= 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>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> <div class="field">
<div class="field"> <%= f.label :password %><br />
<%= f.label :email %><br /> <%= f.password_field :password, autocomplete: "off" %>
<%= f.email_field :email, autofocus: true %> </div>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<% if devise_mapping.rememberable? -%> <% if devise_mapping.rememberable? -%>
<div class="field"> <div class="field">
<%= f.check_box :remember_me %> <%= f.check_box :remember_me %>
<%= f.label :remember_me %> <%= f.label :remember_me %>
</div> </div>
<% end -%> <% end -%>
<div class="actions"> <div class="actions">
<%= f.submit "Log in" %> <%= f.submit "Log in" %>
</div>
<% end %>
</div> </div>
<% end %> </div>
<%= render "users/shared/links" %> <%= render "users/shared/links" %>
...@@ -3,17 +3,23 @@ ...@@ -3,17 +3,23 @@
devise_for :users, controllers: { sessions: "users/sessions" } devise_for :users, controllers: { sessions: "users/sessions" }
devise_for :admins, controllers: { sessions: "admins/sessions" } devise_for :admins, controllers: { sessions: "admins/sessions" }
namespace :admins do namespace :admins do
resources :products resources :products, :carts, :users
end end
get 'index' => 'products#index' get 'index' => 'products#index'
get 'login' => 'sessions#new' get 'login' => 'sessions#new'
get '/admins/destroy/:id' => 'admins/products#destroy', as: 'destroy_product' get '/admins/destroy/:id' => 'admins/products#destroy', as: 'destroy_product'
get '/admins/carts' => 'admins/carts#index' , as: 'admins_carts_index'
get '/admins/users' => 'admins/users#index'
patch "/admins/products/:id/edit"=>'admins/products#edit' patch "/admins/products/:id/edit"=>'admins/products#edit'
patch "/admins/carts/:id/edit" => 'admins/carts#edit'
get 'category/:id' => 'category#show' get 'category/:id' => 'category#show'
get 'products/:id' => 'products#show' get 'products/:id' => 'products#show'
post 'search' =>'products#search'
get 'search' =>'products#search'
get 'cart_products' => 'cart_products#add' get 'cart_products' => 'cart_products#add'
get 'cart_product/remove' => 'cart_products#remove' get 'cart_product/remove' => 'cart_products#remove'
......
require 'test_helper'
class Admins::CartsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class Admins::UsersControllerTest < ActionController::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