Add papertrail and paginate orders on user page
This commit is contained in:
parent
b260d90328
commit
3676068fd9
9 changed files with 38 additions and 20 deletions
15
Gemfile
15
Gemfile
|
@ -29,14 +29,9 @@ gem 'spring', group: :development
|
|||
# add annotations of schema inside models
|
||||
gem 'annotate'
|
||||
|
||||
# Use ActiveModel has_secure_password
|
||||
# gem 'bcrypt', '~> 3.1.7'
|
||||
|
||||
# Use unicorn as the app server
|
||||
# gem 'unicorn'
|
||||
|
||||
# Use Capistrano for deployment
|
||||
# gem 'capistrano-rails', group: :development
|
||||
# Deployment
|
||||
gem 'capistrano', '~> 3.1'
|
||||
gem 'capistrano-rails', '~> 1.1'
|
||||
|
@ -46,19 +41,12 @@ group :production do
|
|||
gem 'mysql2' # Database
|
||||
end
|
||||
|
||||
# Use debugger
|
||||
# gem 'debugger', group: [:development, :test]
|
||||
|
||||
|
||||
#bootstrap
|
||||
gem 'bootstrap-sass', '3.2.0.0'
|
||||
|
||||
#debug stuff
|
||||
gem 'byebug'
|
||||
|
||||
#passwords
|
||||
gem 'bcrypt', '3.1.7'
|
||||
|
||||
#paginate stuff
|
||||
gem 'will_paginate', '3.0.7'
|
||||
gem 'bootstrap-will_paginate', '0.0.10'
|
||||
|
@ -74,3 +62,6 @@ gem 'cancancan'
|
|||
|
||||
#ik wil test data maken dus dit
|
||||
gem 'faker', '1.4.2'
|
||||
|
||||
# Safety first
|
||||
gem 'paper_trail', '~> 4.0.0.beta'
|
||||
|
|
|
@ -99,6 +99,9 @@ GEM
|
|||
net-ssh (>= 2.6.5)
|
||||
net-ssh (2.9.1)
|
||||
orm_adapter (0.5.0)
|
||||
paper_trail (4.0.0.beta2)
|
||||
activerecord (>= 3.0, < 6.0)
|
||||
activesupport (>= 3.0, < 6.0)
|
||||
paperclip (4.2.0)
|
||||
activemodel (>= 3.0.0)
|
||||
activesupport (>= 3.0.0)
|
||||
|
@ -171,7 +174,6 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
annotate
|
||||
bcrypt (= 3.1.7)
|
||||
bootstrap-sass (= 3.2.0.0)
|
||||
bootstrap-will_paginate (= 0.0.10)
|
||||
byebug
|
||||
|
@ -185,6 +187,7 @@ DEPENDENCIES
|
|||
jbuilder (~> 2.0)
|
||||
jquery-rails
|
||||
mysql2
|
||||
paper_trail (~> 4.0.0.beta)
|
||||
paperclip
|
||||
rails (= 4.1.7)
|
||||
sass-rails (~> 4.0.3)
|
||||
|
|
|
@ -3,7 +3,7 @@ class UsersController < ApplicationController
|
|||
|
||||
def show
|
||||
@user = User.find_by_id(params[:id]) || current_user
|
||||
@orders = Order.joins(:products).select(:count, "products.*", "orders.id").where(user: @user).group_by &:id
|
||||
@orders = @user.orders.includes(:products).paginate(page: params[:page])
|
||||
@products = @user.products.select("products.*", "sum(order_products.count) as count").group(:product_id)
|
||||
@categories = @user.products.select("products.category", "sum(order_products.count) as count").group(:category)
|
||||
end
|
||||
|
|
|
@ -164,7 +164,7 @@ class FormattedFormBuilder < ActionView::Helpers::FormBuilder
|
|||
|
||||
def counter_button(button, glyphicon)
|
||||
content_tag :span, class: "input-group-btn" do
|
||||
content_tag :button, class: "btn btn-default #{button}" do
|
||||
content_tag :button, class: "btn btn-default #{button}", type: "button" do
|
||||
content_tag :span, "", class: "glyphicon #{glyphicon}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
class User < ActiveRecord::Base
|
||||
devise :database_authenticatable, :registerable, :rememberable, :trackable
|
||||
has_paper_trail only: [:balance, :admin, :orders_count, :koelkast]
|
||||
has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium,
|
||||
default_url: "http://babeholder.pixoil.com/img/70/70"
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<%= order.created_at %>
|
||||
<%= simple_format(products.map { |p| pluralize(p.count, p.name) }.to_sentence) %>
|
||||
<%= simple_format(order.order_products.map { |p| pluralize(p.count, p.product.name) }.to_sentence) %>
|
||||
|
|
|
@ -11,9 +11,8 @@
|
|||
<% if @user.orders.any? %>
|
||||
<div class="col-md-6">
|
||||
<h3>Orders (<%= @user.orders_count %>)</h3>
|
||||
<% @orders.each do |k,v| %>
|
||||
<%= render 'orders/order', order: v.first, products: v %>
|
||||
<% end %>
|
||||
<%= render @orders %>
|
||||
<%= will_paginate @orders %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
13
db/migrate/20150209113630_create_versions.rb
Normal file
13
db/migrate/20150209113630_create_versions.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class CreateVersions < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :versions do |t|
|
||||
t.string :item_type, :null => false
|
||||
t.integer :item_id, :null => false
|
||||
t.string :event, :null => false
|
||||
t.string :whodunnit
|
||||
t.text :object
|
||||
t.datetime :created_at
|
||||
end
|
||||
add_index :versions, [:item_type, :item_id]
|
||||
end
|
||||
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150209101442) do
|
||||
ActiveRecord::Schema.define(version: 20150209113630) do
|
||||
|
||||
create_table "order_products", force: true do |t|
|
||||
t.integer "order_id"
|
||||
|
@ -66,4 +66,15 @@ ActiveRecord::Schema.define(version: 20150209101442) do
|
|||
t.boolean "koelkast", default: false
|
||||
end
|
||||
|
||||
create_table "versions", force: true do |t|
|
||||
t.string "item_type", null: false
|
||||
t.integer "item_id", null: false
|
||||
t.string "event", null: false
|
||||
t.string "whodunnit"
|
||||
t.text "object"
|
||||
t.datetime "created_at"
|
||||
end
|
||||
|
||||
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue