2014-11-06 16:25:27 +01:00
|
|
|
class UsersController < ApplicationController
|
2015-02-12 14:39:58 +01:00
|
|
|
load_and_authorize_resource
|
|
|
|
|
2014-11-06 16:25:27 +01:00
|
|
|
def show
|
2015-01-09 12:31:14 +01:00
|
|
|
@user = User.find_by_id(params[:id]) || current_user
|
2015-02-09 13:23:38 +01:00
|
|
|
@orders = @user.orders.includes(:products).paginate(page: params[:page])
|
2015-02-09 17:06:24 +01:00
|
|
|
@products = @user.products.select("products.*", "sum(order_items.count) as count").group(:product_id)
|
|
|
|
@categories = @user.products.select("products.category", "sum(order_items.count) as count").group(:category)
|
2014-11-06 16:25:27 +01:00
|
|
|
end
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2014-11-23 21:12:31 +01:00
|
|
|
def index
|
2015-01-06 20:18:01 +01:00
|
|
|
@users = User.members
|
2014-11-23 21:12:31 +01:00
|
|
|
end
|
2014-12-09 22:32:54 +01:00
|
|
|
|
|
|
|
def destroy
|
2015-02-10 07:15:25 +01:00
|
|
|
@user = User.find(params[:id])
|
|
|
|
@user.destroy
|
2014-12-09 22:32:54 +01:00
|
|
|
flash[:success] = "Succesfully removed user"
|
2015-01-15 00:39:34 +01:00
|
|
|
redirect_to action: :index
|
2014-12-09 22:32:54 +01:00
|
|
|
end
|
|
|
|
|
2014-12-10 14:18:56 +01:00
|
|
|
def dagschotel
|
|
|
|
user = User.find(params[:user_id])
|
|
|
|
user.dagschotel = Product.find(params[:product_id])
|
2014-12-17 07:31:51 +01:00
|
|
|
if user.save
|
2015-01-13 13:06:42 +01:00
|
|
|
flash[:success] = "Succesfully updated dagschotel"
|
2014-12-17 07:31:51 +01:00
|
|
|
else
|
|
|
|
flash[:error] = "Error updating dagschotel"
|
|
|
|
end
|
2014-12-10 14:18:56 +01:00
|
|
|
redirect_to edit_user_registration_path(user)
|
|
|
|
end
|
2014-11-06 16:25:27 +01:00
|
|
|
end
|