tap/app/controllers/users_controller.rb

57 lines
1.2 KiB
Ruby
Raw Normal View History

2014-11-06 16:25:27 +01:00
class UsersController < ApplicationController
2015-02-12 14:39:58 +01:00
load_and_authorize_resource
2015-09-14 20:26:16 +02:00
before_action :init, only: :show
2015-02-12 14:39:58 +01:00
2014-11-06 16:25:27 +01:00
def show
end
2014-11-06 18:30:53 +01:00
2015-03-20 02:21:56 +01:00
def edit
end
def update
if @user.update_attributes(user_params)
flash[:success] = "Successfully updated!"
redirect_to @user
2015-03-20 02:21:56 +01:00
else
2015-09-01 17:40:18 +02:00
@user.reload
2015-03-20 02:21:56 +01:00
render 'edit'
end
end
2015-03-19 14:59:37 +01:00
def edit_dagschotel
@dagschotel = @user.dagschotel
@products = Product.for_sale
@categories = Product.categories
2015-03-19 14:59:37 +01:00
end
def update_dagschotel
2015-09-14 20:26:16 +02:00
@user.dagschotel = Product.find(params[:product_id])
@user.save
flash[:success] = "Succesfully updated dagschotel"
2015-09-14 20:26:16 +02:00
redirect_to @user
end
def quickpay
order = @user.orders.build
2015-09-18 15:53:45 +02:00
order.order_items.build(count: 1, product: @user.dagschotel)
2015-09-14 20:26:16 +02:00
if order.save
2015-09-18 15:53:45 +02:00
flash[:success] = "Quick pay succeeded. #{view_context.link_to("Undo", [@user, order], method: :delete)}."
2015-09-14 20:26:16 +02:00
else
flash[:error] = order.errors.full_messages.first
end
redirect_to root_path
2014-12-10 14:18:56 +01:00
end
2015-03-19 14:59:37 +01:00
private
2015-03-20 02:21:56 +01:00
def user_params
params.require(:user).permit(:avatar, :private)
2015-03-20 02:21:56 +01:00
end
2015-09-01 17:40:18 +02:00
def init
@user = User.find_by_id(params[:id]) || current_user
end
2014-11-06 16:25:27 +01:00
end