Some changes to user profile page and other fixes
This commit is contained in:
parent
aa97b51ca6
commit
49dc9201b6
6 changed files with 24 additions and 12 deletions
|
@ -4,6 +4,8 @@ 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
|
||||
@products = @user.products.select("products.*", "count(products.id) as count").group(:product_id)
|
||||
@categories = @user.products.select("products.category", "count(products.category) as count").group(:category)
|
||||
end
|
||||
|
||||
def index
|
||||
|
@ -20,7 +22,7 @@ class UsersController < ApplicationController
|
|||
user = User.find(params[:user_id])
|
||||
user.dagschotel = Product.find(params[:product_id])
|
||||
if user.save
|
||||
flash[:success] = "Succesfully removed user"
|
||||
flash[:success] = "Succesfully updated dagschotel"
|
||||
else
|
||||
flash[:error] = "Error updating dagschotel"
|
||||
end
|
||||
|
|
|
@ -31,6 +31,7 @@ class User < ActiveRecord::Base
|
|||
has_attached_file :avatar, styles: { medium: "100x100>" }, default_style: :medium, default_url: "http://babeholder.pixoil.com/img/70/70"
|
||||
|
||||
has_many :orders, -> { includes :products }
|
||||
has_many :products, through: :orders
|
||||
belongs_to :dagschotel, class_name: 'Product'
|
||||
|
||||
validates :nickname, presence: true, uniqueness: true
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
<%- headers = ['nickname', 'schulden'] -%>
|
||||
<%= CSV.generate_line headers %>
|
||||
<%- @users.each do |user| -%>
|
||||
<%= CSV.generate_line([user.nickname, user.balance]) %>
|
||||
<%- end -%>
|
||||
<%= CSV.generate_line headers -%>
|
||||
<% @users.each do |user| %><%= CSV.generate_line([user.nickname, user.balance]) %><% end %>
|
||||
|
|
3
app/views/products/_category.html.erb
Normal file
3
app/views/products/_category.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<p>
|
||||
<%= pluralize(category.count, category.category) %>
|
||||
</p>
|
3
app/views/products/_product_row.html.erb
Normal file
3
app/views/products/_product_row.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<p>
|
||||
<%= pluralize(product.count, product.name) %>
|
||||
</p>
|
|
@ -9,13 +9,18 @@
|
|||
</div>
|
||||
|
||||
<% if @user.orders.any? %>
|
||||
<div>
|
||||
<h3>Orders (<%= @user.orders.count %>)</h3>
|
||||
<ol class="orders">
|
||||
<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 %>
|
||||
</ol>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="col-md-6">
|
||||
<h3>Products</h3>
|
||||
<%= render partial: "products/product_row", collection: @products, as: :product %>
|
||||
<h4>Categories</h4>
|
||||
<%= render partial: "products/category", collection: @categories %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue