tap/app/controllers/users_controller.rb

60 lines
1.3 KiB
Ruby
Raw Normal View History

2014-11-06 15:25:27 +00:00
class UsersController < ApplicationController
2015-02-12 13:39:58 +00:00
load_and_authorize_resource
2015-09-14 18:26:16 +00:00
before_action :init, only: :show
2015-02-12 13:39:58 +00:00
2014-11-06 15:25:27 +00:00
def show
end
2014-11-06 17:30:53 +00:00
2015-03-20 01:21:56 +00:00
def edit
end
def update
if @user.update_attributes(user_params)
flash[:success] = "Successfully updated!"
redirect_to @user
2015-03-20 01:21:56 +00:00
else
2015-09-01 15:40:18 +00:00
@user.reload
2015-03-20 01:21:56 +00:00
render 'edit'
end
end
2015-03-19 13:59:37 +00:00
def edit_dagschotel
@dagschotel = @user.dagschotel
@products = Product.for_sale
@categories = Product.categories
2015-03-19 13:59:37 +00:00
end
2015-09-14 18:26:16 +00:00
def quickpay
order = @user.orders.build
2015-09-18 13:53:45 +00:00
order.order_items.build(count: 1, product: @user.dagschotel)
2015-09-14 18:26:16 +00:00
if order.save
2015-10-28 15:57:11 +00:00
respond_to do |format|
2015-10-28 19:48:49 +00:00
format.js { render json: { message: "Quick pay succeeded for #{@user.name}." }, status: :ok }
2015-10-28 15:57:11 +00:00
format.html {
flash[:success] = "Quick pay succeeded."
redirect_to root_path
}
end
2015-09-14 18:26:16 +00:00
else
2015-10-28 15:57:11 +00:00
respond_to do |format|
format.js { head :unprocessable_entity }
format.html {
flash[:error] = order.errors.full_messages.first
redirect_to root_path
}
end
2015-09-14 18:26:16 +00:00
end
2014-12-10 13:18:56 +00:00
end
2015-03-19 13:59:37 +00:00
private
2015-03-20 01:21:56 +00:00
def user_params
2015-09-22 18:06:50 +00:00
params.require(:user).permit(:avatar, :private, :dagschotel_id)
2015-03-20 01:21:56 +00:00
end
2015-09-01 15:40:18 +00:00
def init
@user = User.find_by_id(params[:id]) || current_user
end
2014-11-06 15:25:27 +00:00
end